I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 51036 Accepted Submission (s): 20011
Problem description Many schools are popular for a comparative habit. Teachers like to ask, from XXX to XXX, the highest score is how much.
This makes many students very disgusted.
Whether you like it or not, now you need to do is to follow the teacher's request, write a program, mock teacher's inquiry. Of course, teachers sometimes need to update a student's grades.
Input This topic contains multiple sets of tests, please handle to the end of the file.
On the first line of each test, there are two positive integers N and M (0<n<=200000,0<m<5000), which represent the number of students and the number of operations respectively.
Student ID numbers are numbered from 1 to N, respectively.
The second line contains n integers representing the initial scores of the N students, of which the number of I represents the student's score for ID i.
Then there's M-line. Each line has a character C (only ' Q ' or ' U '), and two positive integers, A/b.
When C is ' Q ', it indicates that this is a query operation, which asks for the highest number of students whose IDs are from a to B (including A, a).
When C is ' U ', it indicates that this is an update operation that requires the student with ID A to change the grade to B.
Output outputs the highest score in a row for each query operation.
Sample INPUT5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
Sample Output5659
HintHuge input,the C function scanf () would work better than CIN
Authorlinle Segment Tree Detailed: 1. Baidu Encyclopedia Http://baike.baidu.com/link?url=gw8We703y-rtvoaibGYuxVYBdY3_ VEGQQDXL7J0TWIU2OJDFIUBIG4WN3IHSHHMJVAWO1PXZZQEZB8LE___9CA2. Turn CF Seniors: http://blog.csdn.net/zip_fan/article/details /46775633
#include <cstdio>#include<cstring>#include<utility>#include<queue>using namespacestd;#defineN 200002intt,n,x,y,m;inttre[4*N];Chars[Ten];voidBuildintNumintLeintRI) { if(le==RI) {scanf ("%d",&Tre[num]); return ; } intMid= (Le+ri)/2; Build (Num*2, Le,mid); Build (Num*2+1, mid+1, RI); Tre[num]=max (tre[num*2],tre[num*2+1]);}voidUpdateintNumintLeintRiintXinty) { if(le==RI) {Tre[num]=y; return; } intMid= (Le+ri)/2; if(x<=mid) update (NUM*2, le,mid,x,y);//Update the left ElseUpdate (Num*2+1, mid+1, ri,x,y);//update to the rightTre[num]=max (tre[num*2],tre[num*2+1]);}intQueryintNumintLeintRiintXinty) { if(x<=le&&y>=RI)returnTre[num]; intMid= (Le+ri)/2; intans=0; if(x<=mid) ans=max (Ans,query (num*2, le,mid,x,y)); if(y>mid) ans=max (Ans,query (num*2+1, mid+1, ri,x,y)); returnans;}intMain () {//scanf ("%d", &t); //int ha=0;//While (t--)// { while(~SCANF ("%d%d",&n,&m) {Build (1,1, N); //printf ("Case%d:\n", ++ha); while(m--) {scanf ("%s", s); if(s[0]=='U') {scanf ("%d%d",&x,&y); Update (1,1, N,x,y); } if(s[0]=='Q') {scanf ("%d%d",&x,&y); printf ("%d\n", Query (1,1, n,x,y)); } } } return 0;}
HDU1754 (segment tree)