Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 70156 Accepted Submission(s): 27168
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<queue> 7 #include<map> 8 #include<set> 9 #include<vector> 10 #include<cstdlib> 11 #include<string> 12 #define eps 0.000000001 13 typedef long long ll; 14 typedef unsigned long long LL; 15 using namespace std; 16 const int N=200000+100; 17 struct node{ 18 int l,r; 19 int val; 20 }tree[N*4]; 21 void pushup(int pos){ 22 tree[pos].val=max(tree[pos<<1].val,tree[pos<<1|1].val); 23 } 24 void build(int l,int r,int pos){ 25 tree[pos].r=r; 26 tree[pos].l=l; 27 tree[pos].val=0; 28 if(tree[pos].l==tree[pos].r){ 29 return; 30 } 31 int mid=(l+r)>>1; 32 build(l,mid,pos<<1); 33 build(mid+1,r,pos<<1|1); 34 pushup(pos); 35 } 36 void update(int x,int y,int pos){ 37 if(tree[pos].l==x&&x==tree[pos].r){ 38 tree[pos].val=y; 39 return; 40 } 41 int mid=(tree[pos].l+tree[pos].r)>>1; 42 if(x>mid){ 43 update(x,y,pos<<1|1); 44 } 45 else{ 46 update(x,y,pos<<1); 47 } 48 pushup(pos); 49 } 50 int query(int x,int y,int pos){ 51 if(tree[pos].l>=x&&tree[pos].r<=y){ 52 return tree[pos].val; 53 } 54 int ans=0; 55 int mid=(tree[pos].l+tree[pos].r)>>1; 56 if(x<=mid){ 57 ans=max(ans,query(x,y,pos<<1)); 58 } 59 if(y>mid){ 60 ans=max(ans,query(x,y,pos<<1|1)); 61 } 62 return ans; 63 } 64 int main(){ 65 int m,n; 66 while(scanf("%d%d",&n,&m)!=EOF){ 67 getchar(); 68 build(1,n,1); 69 int x; 70 for(int i=1;i<=n;i++){ 71 scanf("%d",&x); 72 update(i,x,1); 73 } 74 char str[10]; 75 int a,b; 76 int ans; 77 while(m--){ 78 scanf("%s%d%d",str,&a,&b); 79 //cout<<2<<endl; 80 if(str[0]==‘U‘){ 81 update(a,b,1); 82 } 83 else{ 84 ans=query(a,b,1); 85 printf("%d\n",ans); 86 } 87 } 88 } 89 }
原文:http://www.cnblogs.com/Aa1039510121/p/6486042.html