标签:src ons 技术分享 style value end code event str
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<iostream> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=2e5+10; 8 #define lson l,m,i<<1 9 #define rson m+1,r,i<<1|1 10 typedef struct Node 11 { 12 int l,r; 13 int mid() 14 { 15 return (l+r)/2.0; 16 } 17 int value; 18 } Node; 19 Node node[MAXN<<2]; 20 void push_up(int i) 21 { 22 node[i].value=max(node[i<<1].value,node[i<<1|1].value); 23 } 24 void Build(int l,int r,int i) 25 { 26 node[i].l=l; 27 node[i].r=r; 28 node[i].value=0; 29 if(l==r) 30 { 31 scanf("%d",&node[i].value); 32 return ; 33 } 34 int m=node[i].mid(); 35 Build(lson); 36 Build(rson); 37 push_up(i); 38 } 39 int M; 40 void query(int l,int r,int i) 41 { 42 if(node[i].l==l&&node[i].r==r) 43 { 44 M=max(node[i].value,M); 45 return; 46 } 47 int m=node[i].mid(); 48 if(r<=m) 49 query(l,r,i<<1); 50 else 51 { 52 if(l>m) 53 query(l,r,i<<1|1); 54 else 55 { 56 query(lson); 57 query(rson); 58 } 59 } 60 } 61 void update(int l,int r,int i,int v,int num) 62 { 63 if(l==r&&l==num) 64 { 65 node[i].value=v; 66 return; 67 } 68 int m=node[i].mid(); 69 if(m>=num) 70 update(l,m,i<<1,v,num); 71 else 72 { 73 update(m+1,r,i<<1|1,v,num); 74 } 75 push_up(i); 76 } 77 int main() 78 { 79 int m,n,a,b; 80 char s[1234]; 81 while(scanf("%d%d",&n,&m)!=-1) 82 { 83 Build(1,n,1); 84 while(m--) 85 { 86 scanf(" %s%d%d",&s,&a,&b); 87 if(s[0]==‘Q‘) 88 { 89 M=0; 90 query(a,b,1); 91 cout<<M<<endl; 92 } 93 else 94 { 95 update(1,n,1,b,a); 96 } 97 } 98 } 99 }
标签:src ons 技术分享 style value end code event str
原文地址:https://www.cnblogs.com/moomcake/p/9409668.html