1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| #include<stdio.h> #include<cstring> #include<algorithm> #define LL long long #define INIT(a,b) memset(a,b,sizeof(a)) using namespace std; struct Tree{ int num,l,r; }tree[1000007]; void build(int l,int r,int d){ tree[d]=(Tree){-1000,l,r}; if(l==r)return ; int mid=(tree[d].l+tree[d].r)/2; build(l,mid,d<<1); build(mid+1,r,d<<1|1); } void update(int a,int b,int d){ if(tree[d].l==tree[d].r){ tree[d].num=b; return; } int mid=(tree[d].l+tree[d].r)/2; if(a<=mid) update(a,b,d<<1); else update(a,b,d<<1|1); tree[d].num=max(tree[d<<1].num,tree[d<<1|1].num); } int find(int l,int r,int d){ if(tree[d].l==l&&tree[d].r==r) return tree[d].num; int mid=(tree[d].l+tree[d].r)/2; if(r<=mid) return find(l,r,d<<1); else if(l>mid) return find(l,r,d<<1|1); else return max(find(l,mid,d<<1),find(mid+1,r,d<<1|1)); } int main(){ int n,m,tem; while(~scanf("%d %d",&n,&m)){ build(1,n,1); for(int i=1;i<=n;i++){ scanf("%d",&tem); update(i,tem,1); } char s[5]; int x,y; while(m--){ scanf("%s",s); scanf("%d %d",&x,&y); if(s[0]=='Q') printf("%lld\n",find(x,y,1)); else update(x,y,1); } } return 0; }
|