Interval Cubing

这种数学题谁顶得住啊。

因为 (3 ^ 48) % (mod - 1)为 1 , 所以48个一个循环节, 用线段树直接维护。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); int n, q; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
int a[N << ][], lazy[N << ]; inline void pull(int rt) {
for(int i = ; i < ; i++) {
a[rt][i] = a[rt << ][i] + a[rt << | ][i];
if(a[rt][i] >= mod) a[rt][i] -= mod;
}
} inline void push(int rt) {
lazy[rt] %= ;
if(lazy[rt]) {
lazy[rt << ] += lazy[rt];
lazy[rt << | ] += lazy[rt];
rotate(a[rt << ], a[rt << ] + lazy[rt], a[rt << ] + );
rotate(a[rt << | ], a[rt << | ] + lazy[rt], a[rt << | ] + );
lazy[rt] = ;
}
} void build(int l, int r, int rt) {
if(l == r) {
scanf("%d", &a[rt][]);
a[rt][] %= mod;
for(int i = ; i < ; i++)
a[rt][i] = 1LL * a[rt][i - ] * a[rt][i - ] % mod * a[rt][i - ] % mod;
return;
}
int mid = l + r >> ;
build(lson); build(rson);
pull(rt);
} void update(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) {
lazy[rt]++;
rotate(a[rt], a[rt] + , a[rt] + );
return;
}
push(rt);
int mid = l + r >> ;
if(L <= mid) update(L, R, lson);
if(R > mid) update(L, R, rson);
pull(rt);
} int query(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) return a[rt][];
push(rt);
int mid = l + r >> ;
if(R <= mid) return query(L, R, lson);
else if(L > mid) return query(L, R, rson);
else return (query(L, R, lson) + query(L, R, rson)) % mod;
} int main() {
scanf("%d", &n);
build(, n, );
scanf("%d", &q);
while(q--) {
int t, L, R;
scanf("%d%d%d", &t, &L, &R);
if(t == ) {
printf("%d\n", query(L, R, , n, ));
} else {
update(L, R, , n, );
}
}
return ;
} /*
*/

Codeforces 311D Interval Cubing 数学 + 线段树 (看题解)的更多相关文章

  1. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  2. Codeforces 765F Souvenirs 线段树 + 主席树 (看题解)

    Souvenirs 我们将询问离线, 我们从左往右加元素, 如果当前的位置为 i ,用一棵线段树保存区间[x, i]的答案, 每次更新完, 遍历R位于 i 的询问更新答案. 我们先考虑最暴力的做法, ...

  3. [Codeforces]817F. MEX Queries 离散化+线段树维护

    [Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...

  4. Codeforces 834D The Bakery 【线段树优化DP】*

    Codeforces 834D The Bakery LINK 题目大意是给你一个长度为n的序列分成k段,每一段的贡献是这一段中不同的数的个数,求最大贡献 是第一次做线段树维护DP值的题 感觉还可以, ...

  5. Codeforces 1172F Nauuo and Bug [线段树]

    Codeforces 思路 定义\(f_{l,r}(x)\)表示数\(x\)从\(l\)进去\(r\)出来的时候会变成什么样子.容易发现这个函数是个分段函数,每一段都是斜率为1的一次函数,并且段数就是 ...

  6. codeforces 22E XOR on Segment 线段树

    题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...

  7. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

  8. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  9. codeforces 675E Trains and Statistic 线段树+贪心统计

    分析:这个题刚看起来无从下手 但是我们可以先简化问题,首先可以固定起点i,求出i+1到n的最小距离 它可以到达的范围是[i+1,a[i]],贪心的想,我们希望换一次车可以到达的距离尽量远 即:找一个k ...

随机推荐

  1. ansible笔记(6):常用模块之命令类模块

    ansible笔记():常用模块之命令类模块 command模块 command模块可以帮助我们在远程主机上执行命令 注意:使用command模块在远程主机中执行命令时,不会经过远程主机的shell处 ...

  2. 【进阶3-1期】JavaScript深入之史上最全--5种this绑定全面解析(转)

    这是我在公众号(高级前端进阶)看到的文章,现在做笔记  https://github.com/yygmind/blog/issues/20 this的绑定规则总共有下面5种. 1.默认绑定(严格/非严 ...

  3. python1113

    点点滴滴才可以来开距离,人与人的差距是在点点滴滴中拉开的 break 语句可以跳出 for 和 while 的循环体的当前循环 continue语句被用来告诉Python跳过当前循环块中的剩余语句,然 ...

  4. Oracle 之 外部表

    一.外部表概述 外部表只能在Oracle 9i 之后来使用.简单地说,外部表,是指不存在于数据库中的表. 通过向Oracle 提供描述外部表的元数据,我们可以把一个操作系统文件当成一个只读的数 据库表 ...

  5. ORACL内部异常:

    ORACL内部异常: ORA-00001: 违反唯一约束条件 (.) ORA-00017: 请求会话以设置跟踪事件 ORA-00018: 超出最大会话数 ORA-00019: 超出最大会话许可数 OR ...

  6. JAVA图书管理系统汇总共27个

    好多人都在搜索图书管理系统,感觉这个挺受欢迎的,所以整理了一系列的图书管理系统,让大家选择.java图书馆管理系统[优秀毕业设计论文+源码]http://down.51cto.com/data/683 ...

  7. Centos7 设置静态IP地址

    一:  修改网卡配置文件(操作前先备份一下该文件),/etc/sysconfig/network-scripts/ 具体操作如下: 1:进入修改目录 [root@localhost ~]# clear ...

  8. Confluence 6 配置默认语言界面

    Confluence 6 配置默认语言使用的界面. https://www.cwiki.us/display/CONFLUENCEWIKI/Choosing+a+Default+Language

  9. 第一次Java测试及感触

    周四进行了java测试,感触很深,测试的题目是用Java实现一个ATM机的管理系统.最后3个小时后,我没有完成这次测试,但是我找到了自己的很多不足,明确了自己的问题究竟在哪里. 关于这次测试我不会的最 ...

  10. mysql服务器没有响应

    第一步删除c:\windowns下面的my.ini(可以先改成其它的名字也行) 第二步打开对应安装目录下\mysql\bin\winmysqladmin.exe 输入用户名 和密码(也可以忽略此步) ...