题意:给定一个n个数的序列,完成以下3个操作:

  1.给定区间求和

  2.给定区间对x取模

  3.单点修改

对一个数取模,这个数至少折半。于是我们记一个最大值max,如果x>max则不做处理。

  1. #include<stdio.h>
  2. #include<algorithm>
  3. using namespace std;
  4. #define MAXN 1000000+10
  5. typedef long long LL;
  6. struct tree{LL mx,sum;}tr[MAXN<<];
  7. int n,m;
  8. LL a[MAXN];
  9. void build(int k,int l,int r){
  10. if(l==r){
  11. tr[k].mx=tr[k].sum=a[l];
  12. return;
  13. }
  14. int mid=(l+r)>>;
  15. build(k<<,l,mid);
  16. build(k<<|,mid+,r);
  17. tr[k].mx=max(tr[k<<].mx,tr[k<<|].mx);
  18. tr[k].sum=tr[k<<].sum+tr[k<<|].sum;
  19. }
  20. LL sum(int k,int l,int r,int L,int R){
  21. if(l>=L&&r<=R)return tr[k].sum;
  22. int mid=(l+r)>>;
  23. if(R<=mid)return sum(k<<,l,mid,L,R);
  24. else if(L>mid)return sum(k<<|,mid+,r,L,R);
  25. else return sum(k<<,l,mid,L,R)+sum(k<<|,mid+,r,L,R);
  26. tr[k].mx=max(tr[k<<].mx,tr[k<<|].mx);
  27. tr[k].sum=tr[k<<].sum+tr[k<<|].sum;
  28. }
  29. void update(int k,int l,int r,int t,LL x){
  30. if(l==t&&r==t){
  31. tr[k].mx=tr[k].sum=x;
  32. return;
  33. }
  34. int mid=(l+r)>>;
  35. if(t<=mid)update(k<<,l,mid,t,x);
  36. if(t>mid)update(k<<|,mid+,r,t,x);
  37. tr[k].mx=max(tr[k<<].mx,tr[k<<|].mx);
  38. tr[k].sum=tr[k<<].sum+tr[k<<|].sum;
  39. }
  40. void mod(int k,int l,int r,int L,int R,LL x){
  41. if(tr[k].mx<x)return;
  42. if(l==r){
  43. tr[k].mx%=x;
  44. tr[k].sum%=x;
  45. return;
  46. }
  47. int mid=(l+r)>>;
  48. if(R<=mid)mod(k<<,l,mid,L,R,x);
  49. else if(L>mid)mod(k<<|,mid+,r,L,R,x);
  50. else mod(k<<,l,mid,L,R,x),mod(k<<|,mid+,r,L,R,x);
  51. tr[k].mx=max(tr[k<<].mx,tr[k<<|].mx);
  52. tr[k].sum=tr[k<<].sum+tr[k<<|].sum;
  53. }
  54. int main(){
  55. //freopen("mod.in","r",stdin);
  56. //freopen("mod.out","w",stdout);
  57. scanf("%d%d",&n,&m);
  58. for(int i=;i<=n;i++)scanf("%I64d",&a[i]);
  59. build(,,n);
  60. while(m--){
  61. int opt;
  62. scanf("%d",&opt);
  63. if(opt==){
  64. int l,r;
  65. scanf("%d%d",&l,&r);
  66. printf("%I64d\n",sum(,,n,l,r));
  67. }
  68. if(opt==){
  69. int l,r;LL x;
  70. scanf("%d%d%I64d",&l,&r,&x);
  71. mod(,,n,l,r,x);
  72. }
  73. if(opt==){
  74. int k;LL y;
  75. scanf("%d%I64d",&k,&y);
  76. update(,,n,k,y);
  77. }
  78. }
  79. return ;
  80. }

Codeforces 438D The Child and Sequence的更多相关文章

  1. 题解——CodeForces 438D The Child and Sequence

    题面 D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input ...

  2. 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 ...

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

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

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

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

  5. 438D - The Child and Sequence

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  6. CF(438D) The Child and Sequence(线段树)

    题意:对数列有三种操作: Print operation l, r. Picks should write down the value of . Modulo operation l, r, x. ...

  7. Codeforces 438D (今日gg模拟第二题) | 线段树 考察时间复杂度的计算 -_-|||

    Codeforces 438D The Child and Sequence 给出一个序列,进行如下三种操作: 区间求和 区间每个数模x 单点修改 如果没有第二个操作的话,就是一棵简单的线段树.那么如 ...

  8. 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 ...

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

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

随机推荐

  1. 哈尔滨理工大学第六届程序设计团队 H-Permutation

    /* 数学是硬伤......推了半小时推出来一个错误的公式 */ #include <iostream> #include <stdio.h> #include <alg ...

  2. 在ASP.NET Core中使用AOP来简化缓存操作

    前言 关于缓存的使用,相信大家都是熟悉的不能再熟悉了,简单来说就是下面一句话. 优先从缓存中取数据,缓存中取不到再去数据库中取,取到了在扔进缓存中去. 然后我们就会看到项目中有类似这样的代码了. pu ...

  3. Android 开发笔记___图像视图__简单截屏

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  4. HTML学习笔记 w3sCss盒子模型(阴影)(div的一些使用)案例 第十节 (原创) 参考使用表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. HTTPCLIENT 模拟登陆

    第一步构建忽略https验证的httpclient public static CloseableHttpClient getHttpClient() throws Exception { SSLCo ...

  6. PyCharm汉化、破解教程

    汉化 1.将 C:\Program Files (x86)\JetBrains\PyCharm 2017\lib(路径是你的安装路径)目录下的resources_en.jar文件复制出来之后删除,以备 ...

  7. 【Arduino】使用LCD1602和DHT11制作温湿度显示器

    材料: 1.DHT11 2.LCD1602 3.LCD1602 转接板 4.Arduino UNO 5.Arduino 传感器扩展版 那个Arduino UNO 我当初挑类个便宜的山寨货买,结果发来和 ...

  8. Excel、Exchange 和 C# (摘要)

    Excel.Exchange 和 C#Eric GunnersonMicrosoft Corporation 2003年4月21日 摘要:Eric Gunnerson 将向您介绍如何使用 Outloo ...

  9. [转载] Hadoop和Hive单机环境搭建

    转载自http://blog.csdn.net/yfkiss/article/details/7715476和http://blog.csdn.net/yfkiss/article/details/7 ...

  10. ANDROID基础ACTIVITY篇之ACTIVITY的生命周期(二)

    除了Activity的七大生命周期方法外外,还有两个相当重要的方法需要大家熟记那就是onSavelnstanceState()和onRestoreinstanceState(). 那么什么时候会调用这 ...