标签:des style blog http java color
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 35640 Accepted Submission(s): 14034
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #include <iostream> #define Maxx 200010 int str[Maxx],root[Maxx*4]; int n,m; int sum=0; using namespace std; void make_tree(int l,int r,int rt) { if(l==r) { root[rt]=str[l]; return ; } int mid=(l+r)/2; make_tree(l,mid,rt*2); make_tree(mid+1,r,rt*2+1); root[rt]=max(root[rt*2],root[rt*2+1]); } void update(int l,int r,int rt,int a,int b) { if(l == r&&l ==a) { root[rt]=b; return ; } int mid=(l+r)/2; if(a<=mid) { update(l,mid,rt*2,a,b); } else { update(mid+1,r,rt*2+1,a,b); } root[rt]=max(root[rt*2],root[rt*2+1]); } void query(int l,int r,int rt,int left,int right) { if(l==left && r==right) { sum=max(sum,root[rt]); return ; } int mid=(l+r)/2; if(left>mid) query(mid+1,r,rt*2+1,left,right); else if(right<=mid) query(l,mid,rt*2,left,right); else { query(l,mid,rt*2,left,mid); query(mid+1,r,rt*2+1,mid+1,right); } } int main() { int i,j; char str1[2]; int x,y; while(scanf("%d%d",&n,&m)!=EOF) { for(i=1;i<=n;i++) { scanf("%d",&str[i]); } make_tree(1,n,1); for(j=1;j<=m;j++) { scanf("%s%d%d",str1,&x,&y); if(str1[0]==‘Q‘) { sum=0; query(1,n,1,x,y); printf("%d\n",sum); } else { update(1,n,1,x,y); } } } return 0; }
hdu 1754 I Hate It (线段树),布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/ccccnzb/p/3840427.html