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》——第17章:普通题——题目2
2014-04-28 22:05 题目:写个程序判断三连棋哪一方赢了. 解法:三个相同的棋子连成一条横线,竖线或者对角线就判断为赢了. 代码: // 17.2 Write an algorithm t ...
- 《Cracking the Coding Interview》——第14章:Java——题目5
2014-04-26 19:06 题目:Java中的对象反射机制是什么?有鼠么用? 解法:完全不了解,因为java编程经验太少,完全没用过.查了一些资料后,感觉反射机制是个强大并需要边用边体会的强大工 ...
- DOS程序员手册(六)
217页 程序的主要部分后面是主程序所使用的许多小的扩充内存功能.将这些功能组合起 来这些功能便覆盖了扩充内存的操作,尽管还可能想向它们添加错误检查. 程序所包含的函数有: emmtest 检验内 ...
- 1004 Counting Leaves (30 分)(树的遍历)
给出一棵树,问每一层各有多少叶子节点 dfs遍历树 #include<bits/stdc++.h> using namespace std; vector<]; int n,m; i ...
- 聊聊、Java SPI
SPI,Service Provider Interface,服务提供者接口. Animal 接口 package com.rockcode.www.spi; public interface Ani ...
- 九 DIP 依赖倒置原则
首先看定义: 1.高层模块不依赖于低层模块,两者都应该依赖于抽象层 2.抽象不能依赖于细节,细节必须依赖于抽象 首先,模块是个抽象的概念,可以大到一个系统中的子系统作为一个模块,也可以是某个子系统中的 ...
- log4j配置打印mybatis的sql到控制台(复制)
log4j.rootLogger=DEBUG, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender ...
- tomcat调优(Mark)
http://blog.csdn.net/jinwanmeng/article/details/7756591
- easyui中datagrid空数据集不刷新的解决方式
datagrid空间可以异步请求json数据,并将新数据覆盖原有数据,重绘数据表. 但是当回来空数据集的时候,js会产生这样一条错误: TypeError: rows is null for(var ...
- [CF932D]Tree
题目大意:两种操作: $1\;u\;w:$把下一个点挂在$u$下,权值为$w$. $2\;u\;w:$询问从$u$开始的序列的最长长度.序列为从$u$开始的祖先序列中的不严格上升序列 题解:可以把一个 ...