题意:

1~N这些人有一些分数,之后有M条操作。要求支持两种操作:更新其中某个人的成绩,查询[A,B]区间内的人的最高成绩。 ( 0<N<=200000,0<M<5000 )

思路:

简单线段树。

Just Do it.

写这个仅仅是为了有一个模板。

代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. #define N 200020
  6. #define lson l, mid, rt<<1
  7. #define rson mid+1, r, rt<<1|1
  8.  
  9. int tree[N<<];
  10.  
  11. void pushUp(int rt) {
  12. tree[rt] = max(tree[rt<<], tree[rt<<|]);
  13. }
  14.  
  15. void build(int l, int r, int rt) {
  16. if (l == r) {
  17. scanf("%d", &tree[rt]);
  18. return;
  19. }
  20. int mid = (l+r)/;
  21. build(lson);
  22. build(rson);
  23. pushUp(rt);
  24. }
  25.  
  26. int query(int L, int R, int l, int r, int rt) {
  27. if (L <= l && r <= R) {
  28. return tree[rt];
  29. }
  30. int mid = (l+r)/;
  31. int ans = ;
  32. if (L <= mid) ans = max(ans, query(L,R,lson));
  33. if (R > mid) ans = max(ans, query(L,R,rson));
  34. return ans;
  35. }
  36.  
  37. void update(int pos, int v, int l, int r, int rt) {
  38. if (l == r) {
  39. tree[rt] = v;
  40. return;
  41. }
  42. int mid = (l+r)/;
  43. if (pos <= mid) update(pos, v, lson);
  44. if (pos > mid) update(pos, v, rson);
  45. pushUp(rt);
  46. }
  47.  
  48. int main() {
  49. int n ,m;
  50. while (scanf("%d%d", &n, &m) != EOF) {
  51. build(,n,);
  52. char com[];
  53. for (int i = ; i < m; i++) {
  54. int a, b;
  55. scanf("%s%d%d", com, &a, &b);
  56. if (com[] == 'U') {
  57. update(a,b,,n,);
  58. }
  59. if (com[] == 'Q') {
  60. printf("%d\n", query(a,b,,n,));
  61. }
  62. }
  63. }
  64. return ;
  65. }

HDU 1754:I Hate It(线段树-单点更新)的更多相关文章

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

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

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

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

  3. hdu 1754 I Hate It 线段树 单点更新 区间最值

    线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...

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

    #include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...

  5. HDU.1166 敌兵布阵 (线段树 单点更新 区间查询)

    HDU.1166 敌兵布阵 (线段树 单点更新 区间查询) 题意分析 加深理解,重写一遍 代码总览 #include <bits/stdc++.h> #define nmax 100000 ...

  6. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  7. HDU 1166 敌兵布阵(线段树单点更新,板子题)

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

  8. HDU 1166 敌兵布阵(线段树单点更新)

    敌兵布阵 单点更新和区间更新还是有一些区别的,应该注意! [题目链接]敌兵布阵 [题目类型]线段树单点更新 &题意: 第一行一个整数T,表示有T组数据. 每组数据第一行一个正整数N(N< ...

  9. HDU 1166 敌兵布阵(线段树单点更新,区间查询)

    描述 C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况 ...

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

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

随机推荐

  1. Mycat高可用解决方案二(主从复制)

    Mycat高可用解决方案二(主从复制) 系统部署规划 名称 IP 主机名称 用户名/密码 配置 mysql主节点 192.168.199.110 mysql-01 root/hadoop 2核/2G ...

  2. GoF23种设计模式之行为型模式之解释器模式

    一.概述         给定一种语言和其文法的一种表示,再定义一个解释器,该解释器使用表示来解释语言中的句子. 二.适用性              当需要解释一种语言,并且可以将该语言中的句子表示 ...

  3. MIP启发式算法:Variable Neighborhood Decomposition Search

    *本文记录和分享学习到的知识,算不上原创. *参考文献见链接. 本文主要简述和VND VNS RINS很相关的vairable neighborhood decomposition search. 目 ...

  4. C++实现Behavioral - Observer模式 (转)

    转http://patmusing.blog.163.com/blog/static/13583496020101501923571/ 也称为Dependents或Publish-Subscribe模 ...

  5. HDU 5527 Too Rich 贪心

    题意: 有\(10\)种面值为\(1, 5, 10, 20, 50, 100, 200, 500, 1000, 2000\)的纸币,现在你要选最多的数量凑成\(p\)块钱. 分析: 同样分析问题的反面 ...

  6. cache共享问题

    经测试发现,cache在web中与windows service中是不能共享的.但在windows service可以使用cache.

  7. Huawei比赛数据分析

    如何评价2018年华为软件精英挑战赛赛题? https://www.zhihu.com/question/268448695 1.时间与时间戳之间的转换 https://blog.csdn.net/g ...

  8. 25、Base64

    Base64要求把每三个8Bit的字节转换为四个6Bit的字节(3*8 = 4*6 = 24),然后把6Bit再添两位高位0,组成四个8Bit的字节,也就是说,转换后的字符串理论上将要比原来的长1/3 ...

  9. [python学习篇][廖雪峰][2]函数式编程

    函数名也是变量: >>> f = abs >>> f(-10) 10 然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就 ...

  10. [git 学习篇] 提交文件

    http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743256916071d ...