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. AMQP消息队列之RabbitMQ简单示例

    前面一篇文章讲了如何快速搭建一个ActiveMQ的示例程序,ActiveMQ是JMS的实现,那这篇文章就再看下另外一种消息队列AMQP的代表实现RabbitMQ的简单示例吧.在具体讲解之前,先通过一个 ...

  2. python字符串,列表常用操作

    24天养成一个好习惯,第五天! 一.字符串需要掌握的操作 1.取值(索引取值)需要注意的是只能取,不能改 msg = 'hello world' print(msg[4]) 2.切片(顾头不顾尾) m ...

  3. Codeforces 1097G Vladislav and a Great Legend [树形DP,斯特林数]

    洛谷 Codeforces 这题真是妙的很. 通过看题解,终于知道了\(\sum_n f(n)^k​\)这种东西怎么算. update:经过思考,我对这题有了更深的理解,现将更新内容放在原题解下方. ...

  4. Swift 学习- 01 -- 基础部分

    print("世界,你好") var myVariable = 42 myVariable = 50 let myConstant = 42 let implicitinteger ...

  5. django模板导入外部js和css等文件

    1.新建文件夹templates(存放模板文件),新建文件夹media(存放js.css.images文件夹),并把两个文件夹放到了项目的根目录下 2.设定模板路径 设置模板路径比较简单,只要在set ...

  6. GitHub搭配使用Travis CI 进行自动构建服务

    Travis CI (Continuous Integration)持续集成服务 用处:自动监控软件仓库,可以在代码提交后立刻执行自动测试或构建 1.在Github自己的仓库根目录里添加.travis ...

  7. 深入理解 Vue Computed 计算属性

    Computed 计算属性是 Vue 中常用的一个功能,我们今天来说一下他的执行过长 拿官网简单的例子来看一下: <div id="example"> <p> ...

  8. Mysql 5.7 密码策略 ERROR 1819 (HY000)

    Mysql 5.7 默认对用户密码有密码强度要求,如果指定弱密码,会提示如下: ERROR (HY000): Your password does not satisfy the current po ...

  9. spring cloud 使用ribbon简单处理客户端负载均衡

    假如我们的multiple服务的访问量剧增,用一个服务已经无法承载, 我们可以把Hello World服务做成一个集群. 很简单,我们只需要复制Hello world服务,同时将原来的端口8762修改 ...

  10. unicode解码

    var newStr = System.Text.RegularExpressions.Regex.Unescape(str);