HDU 1754 I Hate It(区间最值)
来源:互联网 发布:java jdbc连接池配置 编辑:程序博客网 时间:2024/05/29 14:32
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1754
思路:updata()单点替换,query()区间最值
AC代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#include <map>#include <cstring>#include <climits>#include <cmath>#include <cctype>const int inf = 0x3f3f3f3f;//1061109567typedef long long ll;const int maxn = 200010;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1using namespace std;int value[maxn<<2];void pushup(int rt){ value[rt] = max(value[rt<<1],value[rt<<1|1]);}void build(int l,int r,int rt){ if(l == r) { scanf("%d",&value[rt]); return; } int m = (r + l )>> 1; build(lson); build(rson); pushup(rt);}void updata(int p,int sc,int l,int r,int rt){ if(l == r) { value[rt] = sc; return; } int m = (l + r) >> 1; if(p <= m) updata(p,sc,lson); else updata(p,sc,rson); pushup(rt);}int query(int L,int R,int l,int r,int rt){ if(l >= L && r <= R) return value[rt]; int m = (l + r) >> 1; int ans = 0; if(L <= m) ans = max(ans,query(L,R,lson)); if(R > m) ans = max(ans,query(L,R,rson)); return ans;}int main(){ int n,m; while(scanf("%d%d",&n,&m) != EOF) { build(1,n,1); char op[2]; for(int i=0; i<m; i++) { int a,b; scanf("%s%d%d",op,&a,&b); if(op[0] == 'Q') printf("%d\n",query(a,b,1,n,1)); else updata(a,b,1,n,1); } } return 0;}
0 0
- hdu 1754 I Hate It (查询区间最值)
- HDU 1754 I Hate It(区间最值)
- HDU 1754 I Hate It(区间最值)
- Hdu 1754 I Hate It 单点更新,区间最值
- hdu 1754 I Hate It 线段树-区间最值
- HDU-1754I Hate It 线段树区间最值
- HDU 1754 I Hate It(树状数组求区间最值)
- hdu 1754 I Hate It (线段树功能:单点更新和区间最值)
- hdu 1754 I Hate It(线段树,单点更新,区间最值)
- hdu 1754 I Hate It(线段树之 单点更新+区间最值)
- HDU 1754-I Hate It(线段树:单点更新,区间最值)
- hdu 1754 I Hate It (单点更新,区间最值)
- HDU - 1754 - I Hate It (线段树 - 区间最值)
- hdu(1754)——I hate it(更新节点,区间最值)
- HDU 1754 I Hate It(线段树维护 区间最值)
- HDU 1754 I Hate It(线段树单点替换/区间最值)
- hdu 1754 I Hate It ----->线段树(区间最值,单点更新)
- HDU 1754 I Hate It (splay区间最值单点修改模板)
- JAVA中的UDP通信(多线程)
- workman php开源服务器框架初学(一)
- mysql sql 笔记-获取分组中某个字段的最大的行
- 当界面中出现多个输入框,在弹出输入法,保证输入法不盖住输入框的解决方案
- 过年“飞”回家?携带移动电源登机需注意!
- HDU 1754 I Hate It(区间最值)
- 胜利大逃亡(续)
- Android:Paletee颜色提取用法(调色板)
- 图论训练1A,uva4255 拓扑排序
- Hadoop学习笔记—4.初识MapReduce
- sql经典题
- \r\n
- 欢迎使用CSDN-markdown编辑器
- lightoj 1213 - Fantasy of a Summation 【数学计数】