题意:很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。

  1. 5 6
  2. 1 2 3 4 5
  3. Q 1 5
  4. U 3 6
  5. Q 3 4
  6. Q 4 5
  7. U 2 9
  8. Q 1 5
  1. 5
  2. 6
  3. 5
  4. 9

代码再次优化

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<cmath>
  6. #include<queue>
  7. using namespace std;
  8. int n,m,t;
  9. #define lson l,m,rt<<1
  10. #define rson m+1,r,rt<<1|1
  11. #define root 1,n,1
  12. #define m ((l+r)>>1)
  13. const int maxn=;
  14. int cow[maxn];
  15. int maxx[maxn<<],minn[maxn<<];
  16. int mmax=-,mmin=;
  17. void pushup(int rt){
  18. maxx[rt]=max(maxx[rt<<],maxx[rt<<|]);
  19. }
  20. void build(int l,int r,int rt){
  21. if(l==r){
  22. scanf("%d",&maxx[rt]);
  23. return;
  24. }
  25. build(lson);
  26. build(rson);
  27. pushup(rt);
  28. }
  29. void query(int L,int R,int l,int r,int rt) {
  30. if (L<=l&&r<=R){
  31. mmax=max(mmax,maxx[rt]);
  32. return;
  33. }
  34. int ret=;
  35. if(L<=m) query(L,R,lson);
  36. if(R>m) query(L,R ,rson);
  37. }
  38. void update(int pos,int val,int l,int r,int rt)
  39. {
  40. if(l==r) maxx[rt]=val;
  41. else
  42. {
  43. if(pos<=m) update(pos,val,lson);
  44. else update(pos,val,rson);
  45. pushup(rt);
  46. }
  47. }
  48. int main()
  49. {
  50. int i,j,k;
  51. #ifndef ONLINE_JUDGE
  52. freopen("1.in","r",stdin);
  53. #endif
  54. int q;
  55. while(scanf("%d%d",&n,&q)!=EOF)
  56. {
  57. build(root);
  58. while(q--)
  59. {
  60. char s[];
  61. scanf("%s",s);
  62. int a,b;
  63. if(s[]=='Q')
  64. {
  65. scanf("%d%d",&a,&b);
  66. mmax=-;
  67. query(a,b,root);
  68. printf("%d\n",mmax);
  69. }
  70. else
  71. {
  72. scanf("%d%d",&a,&b);
  73. update(a,b,root);
  74. }
  75. }
  76. }
  77. return ;
  78. }

hdu 1754 单点更新的更多相关文章

  1. HDU 1754 单点更新,求区间最大值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. hdu 1754(单点更新 ,区间最大值)

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  3. HDU 2795 单点更新,区间优先查找(想法)

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HDU 1166 单点更新,区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu 1166 (单点更新+区间求和+裸题)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

  6. hdu 1754 I Hate It (线段树功能:单点更新和区间最值)

    版权声明:本文为博主原创文章.未经博主同意不得转载.vasttian https://blog.csdn.net/u012860063/article/details/32982923 转载请注明出处 ...

  7. HDU 1754 I Hate It 线段树(单点更新,成段查询)

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=1754 题解: 单点更新,成段查询. 代码: #include<iostream> ...

  8. HDU 1754 I Hate It 线段树单点更新求最大值

    题目链接 线段树入门题,线段树单点更新求最大值问题. #include <iostream> #include <cstdio> #include <cmath> ...

  9. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. WebService中方法的相关注意事项

    2014-11-14 在WebService中定义方法,有一些注意的地方: (1) 方法上面需要增加 [WebMethod] 属性,标志该方法是一个WebService方法: (2)方法的返回值可以为 ...

  2. 繁华模拟赛 vicent的字符串

    #include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...

  3. 繁华模拟赛 Vicent与游戏

    #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...

  4. jquery 调用数据

    <body> <div id="aa" style="">hello</div> <div class="b ...

  5. 畅通工程再续(MST)

    畅通工程再续 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  6. (11)UI布局和分辨率适配

    一.Cocos编辑器 自动布局系统主要涉及固定与拉伸属性:   如图,总共可以修改控件的上下左右四个图钉和中间的两个拉伸条六个属性. 效果   1.当打开其中的任意一个图钉时,当前节点与父节点的对应边 ...

  7. cocos基础教程(6)坐标与锚点讲解

    坐标系详解 Cocos2d-x坐标系和OpenGL坐标系相同,都是起源于笛卡尔坐标系.原点为屏幕左下角,x向右,y向上. 世界坐标系(World Coordinate) VS 本地坐标系(Node L ...

  8. 备份还原mysql数据库

    Windows下cmd命令行中备份还原mysql数据库 先cmd 上cd  到mysql的安装bin目录下,然后再运行下面的命令. 例如:cd C:\Program Files\MySQL\MySQL ...

  9. HNU 12826 Balloons Colors

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12826&courseid=268 #include&l ...

  10. Linux常用指令(持续更新)

    (这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) PP真的是一位很有姿势的程序猿,有这样的邻居真好,榜样啊. pwd 当前路径 df  -kh ...