题意:对数列有三种操作:

  1. Print operation l, r. Picks should write down the value of .
  2. Modulo operation l, r, x. Picks should perform assignment a[i] = a[imod x for
    each i (l ≤ i ≤ r).
  3. Set operation k, x. Picks should set the value of a[k] to x (in
    other words perform an assignment a[k] = x).

解法:线段树更新。维护区间最大值ma和区间sum。假设訪问的x小于ma就能够忽略。否则向下更新;

代码:  
  1. /******************************************************
  2. * author:xiefubao
  3. *******************************************************/
  4. #pragma comment(linker, "/STACK:102400000,102400000")
  5. #include <iostream>
  6. #include <cstring>
  7. #include <cstdlib>
  8. #include <cstdio>
  9. #include <queue>
  10. #include <vector>
  11. #include <algorithm>
  12. #include <cmath>
  13. #include <map>
  14. #include <set>
  15. #include <stack>
  16. #include <string.h>
  17. //freopen ("in.txt" , "r" , stdin);
  18. using namespace std;
  19.  
  20. #define eps 1e-8
  21. const double pi=acos(-1.0);
  22. typedef long long LL;
  23. const int Max=100100*2;
  24. const int INF=1000000007;
  25. struct node
  26. {
  27. int l,r;
  28. node * left,*right;
  29. int ma;
  30. LL sum;
  31. } nodes[Max];
  32. int Mid(node* p)
  33. {
  34. return (p->l+p->r)/2;
  35. }
  36. int tot=0;
  37. void buildtree(node* p,int left,int right)
  38. {
  39. p->l=left;
  40. p->r=right;
  41. p->ma=0;
  42. p->sum=0;
  43. if(left==right)
  44. return ;
  45. int mid=(left+right)/2;
  46. tot++;
  47. p->left=nodes+tot;
  48. buildtree(p->left,left,mid);
  49. tot++;
  50. p->right=nodes+tot;
  51. buildtree(p->right,mid+1,right);
  52. }
  53. void update(node* p,int i,int value)
  54. {
  55. if(p->l==i&&p->r==i)
  56. {
  57. p->sum=value;
  58. p->ma=value;
  59. return ;
  60. }
  61. int mid=Mid(p);
  62. if(i<=mid)
  63. update(p->left,i,value);
  64. else
  65. update(p->right,i,value);
  66. p->sum=p->left->sum+p->right->sum;
  67. p->ma=max(p->left->ma,p->right->ma);
  68. }
  69. void update2(node* p,int l,int r,int x)
  70. {
  71. if(p->ma<x)
  72. return;
  73. if(p->l==l&&p->r==r&&l==r)
  74. {
  75. p->sum%=x;
  76. p->ma=p->sum;
  77. return ;
  78. }
  79. int mid=Mid(p);
  80. if(r<=mid)
  81. update2(p->left,l,r,x);
  82. else if(l>mid)
  83. update2(p->right,l,r,x);
  84. else
  85. {
  86. update2(p->left,l,mid,x);
  87. update2(p->right,mid+1,r,x);
  88. }
  89. p->sum=p->left->sum+p->right->sum;
  90. p->ma=max(p->left->ma,p->right->ma);
  91. }
  92. LL query(node* p,int l,int r)
  93. {
  94. if(l==p->l&&r==p->r)
  95. {
  96. return p->sum;
  97. }
  98. int mid=Mid(p);
  99. if(r<=mid)
  100. return query(p->left,l,r);
  101. if(l>mid)
  102. return query(p->right,l,r);
  103. return query(p->left,l,mid)+query(p->right,mid+1,r);;
  104. }
  105. int n,m;
  106. int main()
  107. {
  108. while(scanf("%d%d",&n,&m)==2)
  109. {
  110. tot=0;
  111. buildtree(nodes,0,n+1);
  112. for(int i=1; i<=n; i++)
  113. {
  114. int a;
  115. scanf("%d",&a);
  116. update(nodes,i,a);
  117. }
  118. while(m--)
  119. {
  120. int t;
  121. scanf("%d",&t);
  122. if(t==1)
  123. {
  124. int l,r;
  125. scanf("%d%d",&l,&r);
  126. cout<<query(nodes,l,r)<<endl;
  127. }
  128. else if(t==2)
  129. {
  130. int l,r,x;
  131. scanf("%d%d%d",&l,&r,&x);
  132. update2(nodes,l,r,x);
  133. }
  134. else if(t==3)
  135. {
  136. int i,x;
  137. scanf("%d%d",&i,&x);
  138. update(nodes,i,x);
  139. }
  140. }
  141. }
  142. return 0;
  143. }

CF(438D) The Child and Sequence(线段树)的更多相关文章

  1. Codeforces 438D The Child and Sequence - 线段树

    At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at ...

  2. CodeForces 438D The Child and Sequence (线段树 暴力)

    传送门 题目大意: 给你一个序列,要求在序列上维护三个操作: 1)区间求和 2)区间取模 3)单点修改 这里的操作二很讨厌,取模必须模到叶子节点上,否则跑出来肯定是错的.没有操作二就是线段树水题了. ...

  3. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  4. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模

    D. The Child and Sequence   At the children's day, the child came to Picks's house, and messed his h ...

  5. cf250D. The Child and Sequence(线段树 均摊复杂度)

    题意 题目链接 单点修改,区间mod,区间和 Sol 如果x > mod ,那么 x % mod < x / 2 证明: 即得易见平凡, 仿照上例显然, 留作习题答案略, 读者自证不难. ...

  6. Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)

    题目链接:http://codeforces.com/problemset/problem/438/D 给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x, ...

  7. CF438D The Child and Sequence 线段树

    给定数列,区间查询和,区间取模,单点修改. n,m小于10^5 ...当区间最值小于模数时,就直接返回就好啦~ #include<cstdio> #include<iostream& ...

  8. 2016暑假多校联合---Rikka with Sequence (线段树)

    2016暑假多校联合---Rikka with Sequence (线段树) Problem Description As we know, Rikka is poor at math. Yuta i ...

  9. 2018.07.23 codeforces 438D. The Child and Sequence(线段树)

    传送门 线段树维护区间取模,单点修改,区间求和. 这题老套路了,对一个数来说,每次取模至少让它减少一半,这样每次单点修改对时间复杂度的贡献就是一个log" role="presen ...

随机推荐

  1. DGA特征挖掘

    摘自:https://paper.seebug.org/papers/Archive/drops2/%E7%94%A8%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E8%A ...

  2. matplotlib 可视化 —— 绘制常见图形

    0. 饼状图 plt.pie():Python数据可视化:饼状图 1. 三角形 描点连线,起点和终点相同 triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), ...

  3. List methods

    Python provides methods that operate on lists. For example, append adds a new element to the end of ...

  4. python-网络-tcp

    python-网络-tcp 标签(空格分隔): python TCP[client]-发送数据 from socket import * s = socket(AF_INET, SOCK_STREAM ...

  5. BZOJ 3240 构造矩阵+矩阵快速幂

    思路: ax+b cx+d 构造矩阵+矩阵快速幂 (需要加各种特判,,,,我好像加少了- ) //By SiriusRen #include <cstdio> #include <c ...

  6. linux系统下,11款常见远程桌面控制软件(转载)

    远程控制能够给人们带来很多便利,本文介绍了11款常见的Linux系统下的远程桌面控制工具,总有一款能适合您. 一. Grdc 它是一个用GTK+编写的,适用于gnome桌面环境的远程桌面访问软件.看图 ...

  7. 一篇文章助你理解Python3中字符串编码问题

    前几天给大家介绍了unicode编码和utf-8编码的理论知识,以及Python2中字符串编码问题,没来得及上车的小伙伴们可以戳这篇文章:浅谈unicode编码和utf-8编码的关系和一篇文章助你理解 ...

  8. Git 内部原理 - (7)维护与数据恢复 (8) 环境变量 (9)总结

    维护与数据恢复 有的时候,你需要对仓库进行清理 - 使它的结构变得更紧凑,或是对导入的仓库进行清理,或是恢复丢失的内容. 这个小节将会介绍这些情况中的一部分. 维护 Git 会不定时地自动运行一个叫做 ...

  9. [洛谷P2085]最小函数值

    题目大意:有n个函数,分别为F1,F2,...,Fn.定义Fi(x)=Ai*x^2+Bi*x+Ci (x∈N*).给定这些Ai.Bi和Ci,要求出所有函数的所有函数值中最小的m个(如有重复的要输出多个 ...

  10. ArcGIS api for javascript——地图配置-定制缩放动画,定制缩放框

    描述 本例展示了当用户放大或缩小地图时如何定义地图的动画.zoomDuration和zoomRate是Dojo动画属性,他们确定了动画的duration和帧刷新的rate .这些属性单位是毫秒,zoo ...