Interval Cubing

这种数学题谁顶得住啊。

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

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11.  
  12. using namespace std;
  13.  
  14. const int N = 1e5 + ;
  15. const int inf = 0x3f3f3f3f;
  16. const LL INF = 0x3f3f3f3f3f3f3f3f;
  17. const int mod = ;
  18. const double eps = 1e-;
  19. const double PI = acos(-);
  20.  
  21. int n, q;
  22.  
  23. #define lson l, mid, rt << 1
  24. #define rson mid + 1, r, rt << 1 | 1
  25. int a[N << ][], lazy[N << ];
  26.  
  27. inline void pull(int rt) {
  28. for(int i = ; i < ; i++) {
  29. a[rt][i] = a[rt << ][i] + a[rt << | ][i];
  30. if(a[rt][i] >= mod) a[rt][i] -= mod;
  31. }
  32. }
  33.  
  34. inline void push(int rt) {
  35. lazy[rt] %= ;
  36. if(lazy[rt]) {
  37. lazy[rt << ] += lazy[rt];
  38. lazy[rt << | ] += lazy[rt];
  39. rotate(a[rt << ], a[rt << ] + lazy[rt], a[rt << ] + );
  40. rotate(a[rt << | ], a[rt << | ] + lazy[rt], a[rt << | ] + );
  41. lazy[rt] = ;
  42. }
  43. }
  44.  
  45. void build(int l, int r, int rt) {
  46. if(l == r) {
  47. scanf("%d", &a[rt][]);
  48. a[rt][] %= mod;
  49. for(int i = ; i < ; i++)
  50. a[rt][i] = 1LL * a[rt][i - ] * a[rt][i - ] % mod * a[rt][i - ] % mod;
  51. return;
  52. }
  53. int mid = l + r >> ;
  54. build(lson); build(rson);
  55. pull(rt);
  56. }
  57.  
  58. void update(int L, int R, int l, int r, int rt) {
  59. if(l >= L && r <= R) {
  60. lazy[rt]++;
  61. rotate(a[rt], a[rt] + , a[rt] + );
  62. return;
  63. }
  64. push(rt);
  65. int mid = l + r >> ;
  66. if(L <= mid) update(L, R, lson);
  67. if(R > mid) update(L, R, rson);
  68. pull(rt);
  69. }
  70.  
  71. int query(int L, int R, int l, int r, int rt) {
  72. if(l >= L && r <= R) return a[rt][];
  73. push(rt);
  74. int mid = l + r >> ;
  75. if(R <= mid) return query(L, R, lson);
  76. else if(L > mid) return query(L, R, rson);
  77. else return (query(L, R, lson) + query(L, R, rson)) % mod;
  78. }
  79.  
  80. int main() {
  81. scanf("%d", &n);
  82. build(, n, );
  83. scanf("%d", &q);
  84. while(q--) {
  85. int t, L, R;
  86. scanf("%d%d%d", &t, &L, &R);
  87. if(t == ) {
  88. printf("%d\n", query(L, R, , n, ));
  89. } else {
  90. update(L, R, , n, );
  91. }
  92. }
  93. return ;
  94. }
  95.  
  96. /*
  97. */

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. MySQL--视图view、触发器trigger、事务(start transaction)、存储过程(特殊的数据逻辑处理函数)、流程控制(if,case....)

    mysql致力于项目开发及数据库管理之间解耦合(帮忙封装一些数据处理方法,使应用程序的开发者可以专注于应用程序的开发),但受限于不同部门沟通的成本问题,现阶段直接使用的价值不大. 一.视图(只能sel ...

  2. python 基础 01

    什么是计算机? cpu: 计算机的大脑; 读写速度 3GHZ 内存: (为了提高利用率) 缓冲硬盘和cpu 硬盘: 机械硬盘读写速度70mb/s 计算机里面读写的内容都是01代码 二进制(计算机只认二 ...

  3. 【原创】大叔经验分享(29)cdh5使用已存在的metastore数据库部署hive

    cdh5.16.1使用的hive版本是hive-1.1.0+cdh5.16.1+1431,详见:https://www.cloudera.com/documentation/enterprise/re ...

  4. 文本内容查找grep、文件查找find、正则匹配

    一.文本内容查找工具 grep grep   egrep (文本过滤)   fgrep (不支持正则) 对文本的内容按照指定的匹配模式基于行来进行筛选 格式     grep [选项] 模式 文件 选 ...

  5. VUE 多页面配置(一)

    1. 概述 1.1 说明 项目开发过程中会遇到需要多个主页展示情况,故在vue单页面的基础上进行配置多页面开发以满足此需求. 2. 实例 2.1 页面配置 2.1.1 默认首页 使用vue脚手架搭建后 ...

  6. python第一天,编写用户接口

    作业:编写登陆接口 输入用户名密码 认证成功后显示欢迎信息 输错三次后锁定 流程图: 代码 #!/usr/bin/env python #-*- coding:utf-8 -*- #created b ...

  7. Oracle12c安装和卸载图文教程

    注:本文来源于:<Oracle12c安装和卸载图文教程> 一.安装 1.去官网下载相应的版本 2.下载好的两个压缩文件压缩到一个文件夹中 3.打开上个步骤的文件夹,运行stepup,显示如 ...

  8. Confluence 6 色彩选择器展开的页面

    色彩选择器展开的页面中对色彩的选择配置. https://www.cwiki.us/display/CONFLUENCEWIKI/Customising+Colour+Schemes

  9. 使用Spring配置数据源JdbcTemplate

    c3p0作为演示 1.编写资源文件(db.properties) jdbc.user=root jdbc.password=root jdbc.jdbcUrl=jdbc:mysql://localho ...

  10. Python基础之类方法和静态方法

    小叙一会儿: 通常情况下,在类中定义的所有函数(注意了,这里说的就是所有,跟self啥的没关系,self也只是一个再普通不过 的参数而已)都是对象的绑定方法,对象在调用绑定方法时会自动将自己作为参数传 ...