标签:ios tchar 字符 ons ++ turn scanf col bsp
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 const int maxx=200005; 7 int s[maxx],ms[maxx*4]; 8 9 void pushup(int rt){ 10 ms[rt]=max(ms[rt*2],ms[rt*2+1]); //求最大值 11 } 12 13 void build(int rt,int l,int r){ //建立线段树 14 if(l==r){ 15 ms[rt]=s[l]; 16 return ; 17 } 18 int m=(l+r)/2; 19 build(rt*2,l,m); 20 build(rt*2+1,m+1,r); 21 pushup(rt); 22 } 23 24 int query(int rt,int l,int r,int ql,int qr){//查询最大值 25 if(ql<=l && qr>=r) 26 return ms[rt]; 27 int m=(l+r)/2; 28 int ret=0; 29 if(ql<=m) 30 ret=max(ret,query(rt*2,l,m,ql,qr)); 31 if(qr>m) 32 ret=max(ret,query(rt*2+1,m+1,r,ql,qr)); 33 return ret; 34 } 35 36 void update(int rt,int l,int r,int L,int s){ 37 if(l==r){ 38 ms[rt]=s; 39 return ; 40 } 41 int m=(l+r)/2; 42 if(L<=m) 43 update(rt*2,l,m,L,s); 44 else 45 update(rt*2+1,m+1,r,L,s); 46 pushup(rt); 47 } 48 49 int main(){ 50 int n,m; 51 while(scanf("%d%d",&n,&m)!=EOF){ 52 for(int i=1; i<=n; i++) 53 scanf("%d",&s[i]); 54 build(1,1,n); 55 int a,b; 56 char op; 57 while(m--){ 58 getchar(); 59 scanf("%c%d%d",&op,&a,&b); 60 if(op==‘Q‘) 61 printf("%d\n",query(1,1,n,a,b)); 62 else 63 update(1,1,n,a,b); 64 } 65 } 66 return 0; 67 }
标签:ios tchar 字符 ons ++ turn scanf col bsp
原文地址:https://www.cnblogs.com/cake-lover-77/p/10295211.html