标签:c++ function its mod sample div image mit 个数
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 67373 Accepted Submission(s):
26213
1 #include "bits/stdc++.h" 2 #define lson rt<<1,l,m 3 #define rson rt<<1|1,m+1,r 4 using namespace std; 5 typedef long long LL; 6 const int MAX=200005; 7 int n,m; 8 int c[MAX*4]; 9 inline int mx(int x,int y){return x>y?x:y;} 10 void PushUp(int rt){ 11 c[rt]=mx(c[rt<<1],c[rt<<1|1]); 12 } 13 void build(int rt,int l,int r){ 14 if (l==r){ 15 scanf("%d",&c[rt]); 16 return; 17 } 18 int m=(l+r)>>1; 19 build(lson); 20 build(rson); 21 PushUp(rt); 22 } 23 void update(int rt,int l,int r,int x,int y){ 24 if (l==r && l==x){ 25 c[rt]=y; 26 return; 27 } 28 int m=(l+r)>>1; 29 if (m>=x) 30 update(lson,x,y); 31 else 32 update(rson,x,y); 33 PushUp(rt); 34 } 35 int search(int rt,int l,int r,int x,int y){ 36 if (x<=l && y>=r) 37 return c[rt]; 38 int an(0),m=(l+r)>>1; 39 if (x<=m) 40 an=max(an,search(lson,x,y)); 41 if (y>m) 42 an=max(an,search(rson,x,y)); 43 return an; 44 } 45 int main(){ 46 freopen ("hate.in","r",stdin); 47 freopen ("hate.out","w",stdout); 48 int i,j;char c;int x,y; 49 while (~scanf("%d%d",&n,&m)){ 50 build(1,1,n); 51 for (i=1;i<=m;i++){ 52 c=getchar(); 53 scanf("%c%d%d",&c,&x,&y); 54 if (c==‘Q‘) 55 printf("%d\n",search(1,1,n,x,y)); 56 else 57 update(1,1,n,x,y); 58 } 59 } 60 return 0; 61 }
标签:c++ function its mod sample div image mit 个数
原文地址:http://www.cnblogs.com/keximeiruguo/p/6064115.html