题目链接  ZOJ Monthly, March 2018 Problem F

题意很明确

这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身。

所以开$48$棵线段树,和一个永久标记。当对某个区间操作时对这个区间加一层永久标记。

即当前我要查找的第$x$层,实际找的是第$up[i] + x$层。

时间复杂度$O(48nlogn)$

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
#define ls i << 1
#define rs i << 1 | 1
#define mid ((l + r) >> 1)
#define lson ls, l, mid
#define rson rs, mid + 1, r typedef long long LL; const int N = 1e5 + 10;
const int mod = 99971; int T;
int a[N], nxt[N], cal[N][49];
int t[N << 2][49], up[N << 2];
int n, m; void pushup(int i){
rep(j, 0, 47){
t[i][j] = t[ls][(j + up[ls] + 48) % 48] + t[rs][(j + up[rs] + 48) % 48];
t[i][j] %= mod;
}
} void build(int i, int l, int r){
up[i] = 0;
if (l == r){
rep(j, 0, 47) t[i][j] = cal[a[l]][j];
return;
} build(lson);
build(rson);
pushup(i);
} void update(int i, int l, int r, int L, int R){
if (L <= l && r <= R){
++up[i];
up[i] %= 48;
return;
} if (L <= mid) update(lson, L, R);
if (R > mid) update(rson, L, R);
pushup(i);
} int query(int i, int l, int r, int L, int R, int cnt){
if (L <= l && r <= R){
return t[i][(up[i] + cnt) % 48];
} int ret = 0;
int now = cnt + up[i];
if (L <= mid) ret += query(lson, L, R, now);
if (R > mid) ret += query(rson, L, R, now);
ret %= mod;
return ret;
} int main(){ scanf("%d", &T);
rep(i, 1, mod - 1) nxt[i] = 1ll * i * i * i % mod;
rep(i, 1, mod - 1){
cal[i][0] = i;
rep(j, 1, 47){
cal[i][j] = nxt[cal[i][j - 1]];
}
} while (T--){
scanf("%d%d", &n, &m);
rep(i, 1, n){
scanf("%d", a + i);
a[i] %= mod;
} build(1, 1, n); while (m--){
int op, l, r;
scanf("%d%d%d", &op, &l, &r);
if (op == 1) update(1, 1, n, l, r);
else printf("%d\n", query(1, 1, n, l, r, 0));
}
} return 0;
}

  

ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)的更多相关文章

  1. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  2. ZOJ Monthly, March 2018 题解

    [题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...

  3. HDU 3468:A Simple Problem with Integers(线段树+延迟标记)

    A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...

  4. ZOJ Monthly, March 2018 Solution

    A - Easy Number Game 水. #include <bits/stdc++.h> using namespace std; #define ll long long #de ...

  5. ZOJ Monthly, March 2018

    A. Easy Number Game 贪心将第$i$小的和第$2m-i+1$小的配对即可. #include<cstdio> #include<algorithm> usin ...

  6. POJ3468 A Simple Problem with Integers(线段树延时标记)

    题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...

  7. Data Structure Binary Tree: Largest Independent Set Problem

    http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...

  8. BZOJ4999:This Problem Is Too Simple!(DFS序&树上差分&线段树动态开点:区间修改单点查询)

    Description 给您一颗树,每个节点有个初始值. 现在支持以下两种操作: 1. C i x(0<=x<2^31) 表示将i节点的值改为x. 2. Q i j x(0<=x&l ...

  9. [UVA] 11995 - I Can Guess the Data Structure! [STL应用]

    11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Str ...

随机推荐

  1. Pascal “内存病毒”(骗人的)

    Pascal内存病毒 Chaobs从互联网上获得 pascal病毒虽然说只用Ctrl+Pause Break就可以关闭,但是像有些程序一旦启动,不用等你找到那两个键,就自己运行结束关闭了.比如下面一个 ...

  2. Python 3基础教程11-如何利用pip命令安装包和模块

    本文介绍如何利用pip命令安装Python相关的包和模块.在Python中有些方法或者模块是自带的功能,也叫(build-in),内构函数,实际使用,可能内构函数或者模块不能完成我们的任务,我们就需要 ...

  3. selenium 使用谷歌浏览器模拟wap测试

    /** * 使用谷歌浏览器模拟手机浏览器 * @param devicesName * @author xxx * 创建时间:2017-06-15,更新时间:2017-06-15 * 备注 */ pu ...

  4. 1090 Highest Price in Supply Chain (25 分)(树的遍历)

    求所有叶节点中的最高价以及这个价格的叶节点个数 #include<bits/stdc++.h> using namespace std; ; vector<int>mp[N]; ...

  5. DOM对象转化成jQuery对象

    相比较jQuery转化成DOM,开发中更多的情况是把一个DOM对象加工成jQuery对象.$(参数)是一个多功能的方法,通过传递不同的参数而产生不同的作用. 如果传递给$(DOM)函数的参数是一个DO ...

  6. 移动平台自动化测试:appium(一)

    Appium 是一个开源的,跨平台的自动化测试工具.它支持模拟器(iOS,FirefoxOS,Android)和真机(iOS, Android, FirefoxOS)上的原生应用,混合应用和移动 we ...

  7. CF 1103B Game with modulo

    题目 $a, x$ 是正整数.显然有 \begin{aligned} x \ge 2x \pmod{a} \implies a \le 2x \end{aligned} 若 $x \le a$ 则 \ ...

  8. [bzoj3456] 城市规划 [递推+多项式求逆]

    题面 bzoj权限题面 离线题面 思路 orz Miskcoo ! 先考虑怎么算这个图的数量 设$f(i)$表示$i$个点的联通有标号无向图个数,$g(i)$表示$n$个点的有标号无向图个数(可以不连 ...

  9. Ubuntu扩展系统盘容量,虚拟机下

    安装gparted软件 sudo apt-get install gparted 接下来, 我们开始用Gparted软件扩展Ubuntu目录的容量: 先看操作步骤: 1. 先从windows的 ntf ...

  10. 幸运数字(luckly)

    幸运数字(luckly) 题目描述 A国共有 nn 座城市,这些城市由 TeX parse error: Misplaced & 条道路相连,使得任意两座城市可以互达,且路径唯一.每座城市都有 ...