标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 65040 Accepted Submission(s):
25255
1 #include <cstdio> 2 #include <cmath> 3 #include <cstdlib> 4 #include <cstring> 5 #include <queue> 6 #include <stack> 7 #include <vector> 8 #include <iostream> 9 #include "algorithm" 10 using namespace std; 11 typedef long long LL; 12 13 #define lson rt<<1,l,m 14 #define rson rt<<1|1,m+1,r 15 16 const int MAX=200005; 17 int n,m; 18 int Max[MAX<<2]; 19 20 void PushUp(int rt){Max[rt]=max(Max[rt<<1],Max[rt<<1|1]);} 21 22 void build(int rt,int l,int r){ 23 if (l==r) 24 {scanf("%d",&Max[rt]); 25 return; 26 } 27 int m=(l+r)>>1; 28 build(lson); 29 build(rson); 30 PushUp(rt); 31 } 32 void update(int rt,int l,int r,int x,int y){ 33 if (l==r) 34 {Max[rt]=y; 35 return; 36 } 37 int m=(l+r)>>1; 38 if (x<=m) 39 update(lson,x,y); 40 else 41 update(rson,x,y); 42 PushUp(rt); 43 } 44 int query(int rt,int l,int r,int x,int y){ 45 if (x<=l && r<=y) 46 return Max[rt]; 47 int m=(l+r)>>1; 48 int ans(0); 49 if (x<=m) 50 ans=max(ans,query(lson,x,y)); 51 if (y>m) 52 ans=max(ans,query(rson,x,y)); 53 return ans; 54 } 55 int main(){ 56 freopen ("hate.in","r",stdin); 57 freopen ("hate.out","w",stdout); 58 int i,j; 59 int x,y; 60 char c; 61 while (scanf("%d%d",&n,&m)!=EOF){ 62 build(1,1,n); 63 while (m--) 64 {c=getchar(); 65 while (!(c==‘Q‘ || c==‘U‘)) c=getchar(); 66 scanf("%d%d",&x,&y); 67 if (c==‘Q‘) 68 printf("%d\n",query(1,1,n,x,y)); 69 if (c==‘U‘) 70 update(1,1,n,x,y); 71 }} 72 return 0; 73 }
标签:
原文地址:http://www.cnblogs.com/Michaelzzn/p/5745630.html