题目链接  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. USACO Section1.2 Palindromic Squares 解题报告

    palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  2. 【Neural Network】林轩田机器学习技法

    首先从单层神经网络开始介绍 最简单的单层神经网络可以看成是多个Perception的线性组合,这种简单的组合可以达到一些复杂的boundary. 比如,最简单的逻辑运算AND  OR NOT都可以由多 ...

  3. 在SqlServer中通过SQL语句实现树状查询

    CREATE PROCEDURE [dbo].[GetTree] @Id int AS BEGIN with cte as ( as lvl from Entity where Id = @Id un ...

  4. maven中scope标签作用

    scope 是用来限制 dependency 的作用范围的,影响 maven 项目在各个生命周期时导入的 package 的状态,主要管理依赖的部署. scope 的作用范围: (1)compile: ...

  5. 在Linux下安装ArcGIS10.2

    最近由于工作需要,沉迷可视化无法自拔,一直在研究基于GIS的地图可视化,自己在本机windows搭建了一个ArcGIS服务器,用Tableau和R调用WMS服务成功,不愧是GIS元老级应用,效果超赞. ...

  6. 孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2

    孤荷凌寒自学python第六十三天学习mongoDB的基本操作并进行简单封装2 (完整学习过程屏幕记录视频地址在文末) 今天是学习mongoDB数据库的第九天. 今天继续学习mongoDB的简单操作, ...

  7. 一些优秀的SLAM博主

    http://blog.csdn.net/u010566411 http://blog.csdn.net/qq_18661939/article/details/51782376 http://www ...

  8. iPhone:iOS界面,本地生成随机验证码

    本文博客,模仿杰瑞教育的一篇博文,并在它的基础上,进行了些许更改.同时在重写的过程中,对自己忽略的地方,进行了重新认识,受益匪浅.文章来源:http://www.cnblogs.com/jerehed ...

  9. 小木乃伊到我家 dijkstra + 链表 + 优先队列

    https://ac.nowcoder.com/acm/contest/96/E?&headNav=www&headNav=acm 题目描述   AA的欧尼酱qwb是个考古学家,有一天 ...

  10. [Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) ](A~E)

    A: 题目大意:给你$a,b,c$三条边,可以给任意的边加任意的长度,求最少共加多少长度使得可以构成三角形 题解:排个序,若可以组成,输出$0$,否则输出$c-a-b+1(设a\leqslant b\ ...