ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)
题目链接 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,发现循环节 + 线段树 + 永久标记)的更多相关文章
- ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
- HDU 3468:A Simple Problem with Integers(线段树+延迟标记)
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... ...
- ZOJ Monthly, March 2018 Solution
A - Easy Number Game 水. #include <bits/stdc++.h> using namespace std; #define ll long long #de ...
- ZOJ Monthly, March 2018
A. Easy Number Game 贪心将第$i$小的和第$2m-i+1$小的配对即可. #include<cstdio> #include<algorithm> usin ...
- POJ3468 A Simple Problem with Integers(线段树延时标记)
题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...
- Data Structure Binary Tree: Largest Independent Set Problem
http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...
- 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 ...
- [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 ...
随机推荐
- 《Cracking the Coding Interview》——第1章:数组和字符串——题目8
2014-03-18 02:12 题目:判断一个字符串是否由另一个字符串循环移位而成. 解法:首先长度必须相等.然后将第一个串连拼两次,判断第二个串是否在这个连接串中. 代码: // 1.8 Assu ...
- 编译gearman提示缺少boost
编译german时提示缺少boost: checking for boostlib >= 1.39... configure: We could not detect the boost lib ...
- [网站公告]又拍云API故障造成图片无法上传
大家好,今天早上8:30左右发现又拍云API出现故障,造成图片无法上传,调用图片上传API时出现错误:“The operation has timed out”. 该故障给大家带来了麻烦,望大家谅解! ...
- SpringMVC 集成 Velocity 模板引擎
本文通过 maven 项目中集成 1.引入 SpringMVC 与 Velocity 需要的依赖 <!-- SpringMVC --> <dependency> <gro ...
- 性能测试之siege
一.siege介绍 Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数 ...
- shell之iptables
这五个位置也被称为五个钩子函数(hook functions),也叫五个规则链. 1.PREROUTING (路由前) 2.INPUT (数据包流入口) 3.FORWARD (转发管卡) 4.OUTP ...
- HDU 4714 Tree2cycle 找规律
假设最少删除的边的个数为cost,显然,最终答案即为cost+cost+1 (因为删除一条边,就会增加一个链,所以删除cost条边后,就会有cost+1条链,将这cost+1条链连接起来的代价为cos ...
- table纵横都需要下拉框
table 溢出,下拉框显示不全 <div class="table-scrollable"style="height: 500px; overflow-y: vi ...
- 国际语言代码 Language Code
语言代码 语言名称 af 南非语 af-ZA 南非语 ar 阿拉伯语 ar-AE 阿拉伯语(阿联酋) ar-BH 阿拉伯语(巴林) ar-DZ 阿拉伯语(阿尔及利亚) ar-EG 阿拉伯语(埃及) a ...
- [blockchain-035]eos的部署安装智能合约
0.参考资料 https://github.com/EOSIO/eos/wiki 1. eos的github地址 https://github.com/EOSIO/eos 2.下载eos源码 git ...