标签:
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 53477 Accepted Submission(s): 21005
#include <stdio.h> struct rt { int l,r,max; }t[900020]; int r[900020],SUM=0; int maxa(int x,int y) { return x>=y?x:y; } void make(int left,int right,int num) { t[num].l=left; t[num].r=right; if(left==right) t[num].max=r[left]; else { make(left,(left+right)/2,num+num); make((left+right)/2+1,right,num+num+1); t[num].max=maxa(t[num+num].max,t[num+num+1].max); } } void query(int left,int right,int num) { if(left<=t[num].l&&right>=t[num].r) SUM=t[num].max>SUM?t[num].max:SUM; //判断下,不然错的不要不要的 else { if(left>(t[num].l+t[num].r)/2) query(left,right,num+num+1); if(right<=(t[num].r+t[num].l)/2) query(left,right,num+num); if(left<=(t[num].l+t[num].r)/2&&right>(t[num].l+t[num].r)/2) { query(left,right,num+num); query(left,right,num+num+1); } } } void change(int x,int y,int num) { if(y>t[num].max) t[num].max=y; if(t[num].l==t[num].r) { //t[num].max=y; return ; } if(x>(t[num].r+t[num].l)/2) change(x,y,num+num+1); else change(x,y,num+num); } int main() { int n,m,i,mi,ma,temp; char x; while(scanf("%d %d",&n,&m)!=EOF) { for(i=1;i<=n;i++) { scanf("%d",&r[i]); }//getchar(); make(1,n,1); for(i=0;i<m;i++) { getchar();scanf("%c %d %d",&x,&mi,&ma); //getchar()很重要 if(x==‘Q‘) { SUM=0; query(mi,ma,1); printf("%d\n",SUM); } if(x==‘U‘) change(mi,ma,1); } } return 0; }
标签:
原文地址:http://www.cnblogs.com/zhangfengnick/p/4878951.html