这道题模拟一下可以过,但是我们发现线段树也可以安全水过......

写的线段树只需要滋磁单点修改,区间求max即可

我一开始犯了一个很SB的错误:每次插入修改了t,然后疯狂爆0到怀疑人生...

而且我写的线段树还不明不白的碾了胡雨菲几年前写的。

  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4. using namespace std;
  5. const int N = ;
  6. typedef long long LL;
  7. LL mo;
  8. LL Max[N<<];
  9.  
  10. void build(int l,int r,int o)
  11. {
  12. Max[o]=-;
  13. if(l==r)
  14. {
  15. return;
  16. }
  17. int mid=(l+r)>>;
  18. build(l,mid,o<<);
  19. build(mid+,r,o<<|);
  20. return;
  21. }
  22.  
  23. void add(int x,int v,int l,int r,int o)
  24. {
  25. //printf("add:x=%d v=%d l=%d r=%d o=%d\n",x,v,l,r,o);
  26. if(l==x&&r==x)
  27. {
  28. //printf("Max[%d]=%d\n",o,v);
  29. Max[o]=v;
  30. return;
  31. }
  32. int mid=(l+r)>>;
  33. if(x<=mid)add(x,v,l,mid,o<<);
  34. else add(x,v,mid+,r,o<<|);
  35. Max[o]=max(Max[o<<],Max[o<<|]);
  36. return;
  37. }
  38.  
  39. LL ask(int L,int R,int l,int r,int o)
  40. {
  41. if(L<=l&&r<=R) return Max[o];
  42. if(R<l||r<L) return -;
  43. int mid=(l+r)>>;
  44. return max(ask(L,R,l,mid,o<<),ask(L,R,mid+,r,o<<|));
  45. }
  46.  
  47. int main()
  48. {
  49. LL m,top=,x,t=;char flag;
  50. scanf("%lld%lld",&m,&mo);
  51. build(,m,);
  52. for(int i=;i<=m;i++)
  53. {
  54. cin>>flag>>x;
  55. if(flag=='Q')
  56. {
  57. if(!x) {printf("0\n");continue;}
  58. t=ask(top-x,top-,,m,);
  59. printf("%lld\n",t);
  60. }
  61. else
  62. {
  63.  
  64. add(top,(t+x)%mo,,m,);
  65. top++;
  66. }
  67. }
  68. return ;
  69. }

AC代码:

P1198 最大数 线段树水题的更多相关文章

  1. POJ 3468 A Simple Problem with Integers(线段树水题)

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

  2. hdu 1754 I Hate It(线段树水题)

    >>点击进入原题测试<< 思路:线段树水题,可以手敲 #include<string> #include<iostream> #include<a ...

  3. 【wikioi】1191 数轴染色(线段树+水题)

    http://wikioi.com/problem/1191/ 太水的线段树了,敲了10分钟就敲完了,但是听说还有一种并查集的做法?不明觉厉. #include <cstdio> #inc ...

  4. codeforces 339C Xenia and Bit Operations(线段树水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Bit Operations Xenia the beginn ...

  5. 洛谷 - P1198 - 最大数 - 线段树

    https://www.luogu.org/problemnew/show/P1198 要问区间最大值,肯定是要用线段树的,不能用树状数组.(因为没有逆元?但是题目求的是最后一段,可以改成类似前缀和啊 ...

  6. hdu - 1394 Minimum Inversion Number(线段树水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1394 很基础的线段树. 先查询在更新,如果后面的数比前面的数小肯定会查询到前面已经更新过的值,这时候返回的sum ...

  7. P1198最大数——线段树点修改&&模板题

    题目 题目链接 大意:维护一个数列,有两种操作: 查询操作Q  L:查询当前数列中末尾L个数中的最大的数 插入操作A  n:将n加上t再对D取模,将所得值插入数列末尾 解决方案 由题意知,只有两种操作 ...

  8. codevs 1690 开关灯 线段树水题

    没什么好说的,标记put表示开关是否开着. #include<cstdio> #include<cstring> #include<algorithm> using ...

  9. [ACM_数据结构] Color the ball [线段树水题][数组开大]

    Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次 ...

随机推荐

  1. CSS 尺寸 (Dimension) 实例

    CSS 尺寸 (Dimension) 实例CSS 尺寸属性CSS 尺寸属性允许你控制元素的高度和宽度.同样,还允许你增加行间距. 属性 描述height 设置元素的高度.line-height 设置行 ...

  2. [T-ARA][ORGR]

    歌词来源:http://music.163.com/#/song?id=29343993 作曲 : 4번타자/에스킴 [作曲 : 4p/beon-Ta-c/ja-/e-seu-Kim] 作词 : 4번 ...

  3. 树的最长链-POJ 1985 树的直径(最长链)+牛客小白月赛6-桃花

    求树直径的方法在此转载一下大佬们的分析: 可以随便选择一个点开始进行bfs或者dfs,从而找到离该点最远的那个点(可以证明,离树上任意一点最远的点一定是树的某条直径的两端点之一:树的直径:树上的最长简 ...

  4. Individual Project - Word frequency program——12061154Joy

    Description&Requirement: http://www.cnblogs.com/jiel/p/3978727.html 项目时间估计 理解项目要求: 1h 构建项目逻辑: 1h ...

  5. 20145221 《Java程序设计》实验报告四:Android开发基础

    20145221 <Java程序设计>实验报告四:Android开发基础 实验要求 基于Android Studio开发简单的Android应用并部署测试; 了解Android组件.布局管 ...

  6. CMake系列之三:多个源文件-同一目录

    同一目录,多个源文件 把前面的main.c里面的power函数单独写入到一个MathFunctions.c源文件里,目录下的文件结构如下: ./Demo2 | +--- main.c | +--- M ...

  7. 软件工程(GZSD2015) 第二次作业进度

    贵州师范大学软件工程第二次作业 徐 镇 王铭霞 张 英 涂江枫 张 燕 安 坤 周 娟 杨明颢 杨家堂 罗文豪 娄秀盛 周 娟 李盼 岳庆 张颖 李丽思 邓婷 唐洁 郑倩 尚清丽 陈小丽 毛茸 宋光能 ...

  8. mongoDB的配置和使用

    如何启动mongodb? mongod --dbpath C:\appStore\mongodata //数据库地址 再开一个cmder窗口 进入C:\Program Files\MongoDB\Se ...

  9. js返回值 数组去重

    function myfun(arr){ var arr1 = new Array(); var len = arr.length; ;i <len ;i++){ ) { arr1.push(a ...

  10. Centos7搭建LAMP+Typecho博客

    一.安装Apache的httpd服务 yum install httpd # 安装httpd服务 systemctl start httpd # 启动httpd服务 systemctl status ...