线段树_HDU_1754
来源:互联网 发布:阜宁县网络发言人平台 编辑:程序博客网 时间:2024/06/12 01:18
前面是区间求和,这里是区间求最大值,写着写着,上一个疑惑就解决了
#include<iostream>#include<cstring>#include<cstdio>#define oo 0x3f3f3f3fconst int maxn = 2000010;using namespace std;int tree[maxn<<2];void Max(int t){ int ls = tree[t<<1]; int rs = tree[t<<1|1]; tree[t] = ls>rs?ls:rs;}void build(int l, int r,int rt){ if(l == r) { scanf("%d",&tree[rt]); return; } int mid = (l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); Max(rt);}void updata(int a, int b,int l,int r,int rt){ if(l == r) tree[rt] = b; else { int mid = (l+r)>>1; if(a<=mid) updata(a,b,l,mid,rt<<1); else updata(a,b,mid+1,r,rt<<1|1); Max(rt); }}int query(int a, int b, int l, int r, int rt){ if(a<=l&&r<=b)return tree[rt]; int mid = (l+r)>>1; int ans = -oo; if(a<=mid) ans = max(ans,query(a,b,l,mid,rt<<1)); if(b>mid) ans = max(ans,query(a,b,mid+1,r,rt<<1|1)); return ans;}int main(){ int n,m,a,b; char s[10]; while(scanf("%d%d",&n,&m)!=EOF) { build(1,n,1); while(m--) { scanf("%s",s); scanf("%d%d",&a,&b); if(s[0]=='Q') printf("%d\n",query(a,b,1,n,1)); else updata(a,b,1,n,1); } } return 0;}
0 0
- 线段树_HDU_1754
- 线段树?线段树!
- 线段树?线段树!
- 线段_线段树
- 线段_线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- 线段树
- ngx_listening_s
- modle factory
- R语言支持向量机SVM
- 开发团队周总结流水20150724
- python class __slots__
- 线段树_HDU_1754
- Android ndk 单步调试
- 关于caffe-windows中 compute_image_mean.exe出现的问题
- 效率极低人群之七大习惯------写得很透彻
- 关于iOS push一些问题的理解
- HDU 1232 畅通工程
- 测试人员如何减少产品的遗留bug
- Spark Streaming 流计算优化记录(3)-控制流量与join的地点
- Android完全退出程序