题意:略。

析:裸的线段树。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #define lson l,m,rt<<1
  17. #define rson m+1,r,rt<<1|1
  18. #define freopenr freopen("in.txt", "r", stdin)
  19. #define freopenw freopen("out.txt", "w", stdout)
  20. using namespace std;
  21.  
  22. typedef long long LL;
  23. typedef pair<int, int> P;
  24. const int INF = 0x3f3f3f3f;
  25. const double inf = 0x3f3f3f3f3f3f;
  26. const double PI = acos(-1.0);
  27. const double eps = 1e-8;
  28. const int maxn = 200000 + 5;
  29. const int mod = 1e9 + 7;
  30. const int dr[] = {0, 1, 0, -1, -1, 1, 1, -1};
  31. const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};
  32. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  33. int n, m;
  34. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  35. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  36. inline int Min(int a, int b){ return a < b ? a : b; }
  37. inline int Max(int a, int b){ return a > b ? a : b; }
  38. inline LL Min(LL a, LL b){ return a < b ? a : b; }
  39. inline LL Max(LL a, LL b){ return a > b ? a : b; }
  40. inline bool is_in(int r, int c){
  41. return r >= 0 && r < n && c >= 0 && c < m;
  42. }
  43. int maxv[maxn<<2];
  44.  
  45. void pushup(int rt){ maxv[rt] = Max(maxv[rt<<1], maxv[rt<<1|1]); }
  46.  
  47. void build(int l, int r, int rt){
  48. if(l == r){
  49. scanf("%d", &maxv[rt]);
  50. return ;
  51. }
  52. int m = (l + r) >> 1;
  53. build(lson);
  54. build(rson);
  55. pushup(rt);
  56. }
  57.  
  58. void update(int x, int val, int l, int r, int rt){
  59. if(l == r){
  60. maxv[rt] = val;
  61. return ;
  62. }
  63. int m = (l + r) >> 1;
  64. if(x <= m) update(x, val, lson);
  65. if(x > m) update(x, val, rson);
  66. pushup(rt);
  67. }
  68.  
  69. int query(int L, int R, int l, int r, int rt){
  70. if(L <= l && r <= R) return maxv[rt];
  71. int m = (l + r) >> 1;
  72. int ans = -INF;
  73. if(L <= m) ans = Max(ans, query(L, R, lson));
  74. if(R > m) ans = Max(ans, query(L, R, rson));
  75. return ans;
  76. }
  77.  
  78. int main(){
  79. while(scanf("%d %d", &n, &m) == 2){
  80. build(1, n, 1);
  81. char s[5];
  82. int x, y;
  83. while(m--){
  84. scanf("%s", s);
  85. if(s[0] == 'Q'){
  86. scanf("%d %d", &x, &y);
  87. printf("%d\n", query(x, y, 1, n, 1));
  88. }
  89. else{
  90. scanf("%d %d", &x, &y);
  91. update(x, y, 1, n, 1);
  92. }
  93. }
  94. }
  95. return 0;
  96. }

HDU 1754 I Hate It (线段树)的更多相关文章

  1. hdu 1754 I Hate It 线段树 点改动

    // hdu 1754 I Hate It 线段树 点改动 // // 不多说,裸的点改动 // // 继续练 #include <algorithm> #include <bits ...

  2. HDU 1754 I Hate It(线段树之单点更新,区间最值)

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

  3. HDU 1754 I Hate It 线段树RMQ

    I Hate It Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=175 ...

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

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

  5. HDU 1754 I Hate It(线段树单点替换+区间最值)

    I Hate It [题目链接]I Hate It [题目类型]线段树单点替换+区间最值 &题意: 本题目包含多组测试,请处理到文件结束. 在每个测试的第一行,有两个正整数 N 和 M ( 0 ...

  6. HDU 1754 I Hate It(线段树区间查询,单点更新)

    描述 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感.不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老 ...

  7. HDU 1754 I Hate It (线段树)

    题目链接 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老 ...

  8. hdu 1754 I Hate It 线段树基础题

    Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求, ...

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

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

随机推荐

  1. js实现各种常用排序算法

    1.冒泡排序 var bubbleSort = function (arr) { var flag = true; var len = arr.length; for (var i = 0; i &l ...

  2. 转:LoadRunner负载测试之Windows常见性能计数器,分析服务器性能瓶颈

    发布于2012-10-8,来源:博客园 监测对象 System(系统) l %Total Processor Time 系统中所有处理器都处于繁忙状态的时间百分比,对于多处理器系统来说,该值可以反映所 ...

  3. 【knowledgebase】不要在一个很大的RDD上调用collect

    如果一个RDD很大以至于它的所有元素并不能在driver端机器的内存中存放下,请不要进行如下调用: val values = myVeryLargeRDD.collect()   collect将尝试 ...

  4. java.lang.UnsupportedClassVersionError

    尝试运行出错,出错原因:/tmp/tmp_1458557049226652 exit 1, Exception in thread "main" java.lang.Unsuppo ...

  5. Thinkphp源码分析系列–开篇

    目前国内比较流行的php框架由thinkphp,yii,Zend Framework,CodeIgniter等.一直觉得自己在php方面还是一个小学生,只会用别人的框架,自己也没有写过,当然不是自己不 ...

  6. mysql 不是主键不能删除的保护问题解决办法?

       select * from t_answerexams;      delete from  t_answerexams  where  selectid = 'c4582502-8b27-44 ...

  7. writel(readl(&pwm_timer->tcfg0) | 0xff, &pwm_timer->tcfg0);

    解析这句代码什么意思! 神说:选定预分频器0 为什么? 神说:因为实验中选的是timer1,在预分频器0下: 若选择timer4,该如何写这句代码? 首先看tcfg0中选择预分频器1,在看tcfg1里 ...

  8. canvas画随机闪烁的星星

    canvas画一颗星星: 规则的星星有内切圆和外切圆,每两个点之间的角度是固定的,因此可得到星星的每个点的坐标,画出星星. function drawStars(x,y,radius1,radius2 ...

  9. Myeclipse以及Genymotion工具的使用以及java后台开发小结

    1. 服务端的Servlet程序修改并保存后,需要重启tomcat服务器才能使其修改有效.重新部署web项目是没有什么卵用的. 2. servers选项卡若是移走了看不到,在window-show v ...

  10. Ninject的使用

    摘要 DI容器的一个责任是管理他创建的对象的生命周期.他应该决定什么时候创建一个给定类型的对象,什么时候使用已经存在的对象.他还需要在对象不需要的时候处理对象.Ninject在不同的情况下管理对象的生 ...