此题是一道线段树的裸题,这里只是为了保存我的zkw线段树模板

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. using namespace std;
  5. typedef long long LL;
  6. inline int geti() {
  7. static int Ina; static char Inc; static bool InSign;
  8. InSign = false;
  9. while ((Inc = getchar()) < '0' || Inc >'9') InSign |= Inc == '-';
  10. Ina = Inc - '0';
  11. while ((Inc = getchar()) >= '0' && Inc <= '9') Ina = (Ina << 3) + (Ina << 1) + Inc - '0';
  12. return InSign ? -Ina : Ina;
  13. }
  14. inline void Outi(LL x) {
  15. if (x < 0) putchar('-'), x = -x;
  16. static char buf[20]; static int Len;
  17. Len = 0; while (x) buf[++Len] = x % 10 + '0', x /= 10;
  18. while (Len) putchar(buf[Len--]);
  19. }
  20. const int N = 200005;
  21. int pre, dl[N << 1], dr[N << 1];
  22. LL C[N << 1], ly[N << 1];
  23. #define ls u<<1
  24. #define rs u<<1|1
  25. void Down(const int &u) {
  26. if (ly[u] && u < pre) {
  27. C[ls] += (dr[ls] - dl[ls] + 1) * ly[u];
  28. C[rs] += (dr[rs] - dl[rs] + 1) * ly[u];
  29. ly[ls] += ly[u]; ly[rs] += ly[u];
  30. ly[u] = 0;
  31. }
  32. }
  33. int Stack[30], top;
  34. void Up(int u) {
  35. for (top = 0; u; u >>= 1) Stack[++top] = u;
  36. while (top) Down(Stack[top--]);
  37. }
  38. LL Query(int s, int t) {
  39. LL ret = 0; int lef(0), rig(0);
  40. for (s += pre - 1, t += pre + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
  41. if (~s & 1) (lef ? 1 : (Up(lef = s ^ 1),1)), ret += C[s ^ 1];
  42. if ( t & 1) (rig ? 1 : (Up(rig = t ^ 1),1)), ret += C[t ^ 1];
  43. }
  44. return ret;
  45. }
  46. void Update(int s, int t, const int &val) {
  47. int lef(0), rig(0);
  48. for (s += pre - 1, t += pre + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
  49. if (~s & 1) (lef ? 1 : (Up(lef = s ^ 1),1)), ly[s ^ 1] += val, C[s ^ 1] += (dr[s ^ 1] - dl[s ^ 1] + 1) * (LL)val;
  50. if ( t & 1) (rig ? 1 : (Up(rig = t ^ 1),1)), ly[t ^ 1] += val, C[t ^ 1] += (dr[t ^ 1] - dl[t ^ 1] + 1) * (LL)val;
  51. }
  52. for (lef >>= 1; lef; lef >>= 1) C[lef] = C[lef << 1 | 1] + C[lef << 1];
  53. for (rig >>= 1; rig; rig >>= 1) C[rig] = C[rig << 1 | 1] + C[rig << 1];
  54. }
  55. int main() {
  56. int n = geti(), m = geti();
  57. for (pre = 1; pre <= n + 1; pre <<= 1);
  58. for (int i = 1; i <= n; ++i) C[i + pre] = geti(), dl[i + pre] = dr[i + pre] = i;
  59. for (int i = pre; i; --i) C[i] = C[i << 1] + C[i << 1 | 1], dl[i] = dl[i << 1], dr[i] = dr[i << 1 | 1];
  60. char op; int x, y, z;
  61. while (m--) {
  62. while ((op = getchar()) < 'C' && op > 'Q');
  63. if (op ^ 'C') {
  64. x = geti(), y = geti();
  65. if (x > y) x ^= y ^= x ^= y;
  66. cout << Query(x, y) << endl;
  67. } else {
  68. x = geti(), y = geti(), z = geti();
  69. if (x > y) x ^= y ^= x ^= y;
  70. Update(x, y, z);
  71. }
  72. }
  73. return 0;
  74. }

poj3468 A Simple Problem with Integers(zkw区间修改模板)的更多相关文章

  1. 线段树---poj3468 A Simple Problem with Integers:成段增减:区间求和

    poj3468 A Simple Problem with Integers 题意:O(-1) 思路:O(-1) 线段树功能:update:成段增减 query:区间求和 Sample Input 1 ...

  2. poj3468 A Simple Problem with Integers (线段树区间最大值)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92127   ...

  3. poj------(3468)A Simple Problem with Integers(区间更新)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 60745   ...

  4. POJ 3468 A Simple Problem with Integers(线段树模板之区间增减更新 区间求和查询)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 140120 ...

  5. poj3468 A Simple Problem with Integers (树状数组做法)

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  6. POJ3468 A Simple Problem with Integers 【段树】+【成段更新】

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 57666   ...

  7. POJ3468:A Simple Problem with Integers(线段树模板)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 149972 ...

  8. A Simple Problem with Integers 循环节 修改 平方 找规律 线段树

    A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 ...

  9. POJ3468 A Simple Problem with Integers(数状数组||区间修改的RMQ问题)

    You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...

随机推荐

  1. ref

    ref:  当控制权传递回调用方法时,在方法中对参数的任何更改都将反映在该变量中. 例如: class RefExample { //使用ref返回的函数 static void Method(ref ...

  2. SQL Server 2008 R2——使用数字辅助表(master..spt_values)实现用计数字段对记录进行重复显示

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...

  3. [python]爬虫学习(一)

    要学习Python爬虫,我们要学习的共有以下几点(python2): Python基础知识 Python中urllib和urllib2库的用法 Python正则表达式 Python爬虫框架Scrapy ...

  4. RSA加密算法的简单案例

    RSA加密算法是目前最有影响力的公钥加密算法,它能够抵抗到目前为止已知的绝大多数密码攻击. 那关于RSA加密算法有哪些应用呢?以下举一个数据库身份验证的案例. 在使用数据集进行身份认证时,密码存在数据 ...

  5. 【2016-11-6】【坚持学习】【Day21】【主窗口关闭时,同步关闭它的子窗口】

    本来想用委托实现的.但是又觉得没有必要. 方法如下: public MainWindow() { InitializeComponent(); this.Closing += MainWindow_C ...

  6. TCP/IP四层模型和OSI七层模型

    TCP/IP四层模型 TCP/IP是一组协议的代名词,它还包括许多协议,组成了TCP/IP协议簇.TCP/IP协议簇分为四层,IP位于协议簇的第二层(对应OSI的第三层),TCP位于协议簇的第三层(对 ...

  7. [No000082]Convert和Parse的区别/Convert.ToInt32()与int.Parse()的区别

    (1)这两个方法的最大不同是它们对null值的处理方法: Convert.ToInt32(null)会返回0而不会产生任何异常,但int.Parse(null)则会产生异常. 没搞清楚Convert. ...

  8. Python list

    序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但最常见的是列表和元组. 序列 ...

  9. 配置文件类 Properties

    Properties(配置文件类): 主要用于生产配置文件与读取配置文件的信息. Properties属于集合类,继承于Hashtable. Properties要注意的细节:    1. 如果配置文 ...

  10. IO(七)----转换流

    输入字节流的转换流:InputStreamReader 是字节流通向字符流的桥梁. 输出字节流的转换流:OutputStreamWriter  可以把输出字节流转换成输出字符流 .  是符流通向字节流 ...