I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 65143 Accepted Submission (s): 25299
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 to find the minimum value
#include <cstdio>#include<iostream>#include<algorithm>#defineLson l,m,rt << 1#defineRson M+1,r,rt << 1 | 1using namespacestd;Const intMAXN =222222;ints[maxn<<2];voidPushup (intRT) {S[rt]=max (s[rt<<1],s[rt<<1|1]);}voidBuildintLintRintRT) {//RT represents the number of nodes if(l==R) {scanf ("%d", s+RT); return; } intM= (l+r) >>1; Build (Lson); Build (Rson); Pushup (RT);}voidUpdateintPintScintLintRintRT) { if(l==R) {S[rt]=SC;return; } intM= (l+r) >>1; if(p<=m) update (P,sc,lson); ElseUpdate (P,sc,rson); Pushup (RT);}intQueryintLintRintLintRintRT) { if(l>r| | L>R)return-1; if(L<=L&&R<=R)returnS[rt]; intm = (l+r) >>1; intvv=query (L,r,lson); intVr=query (L,r,rson); returnMax (VV,VR);}intMain () {//freopen ("data.in", "R", stdin); intn,m; while(~SCANF ("%d%d",&n,&m)) {Build (1N1); while(m--){ Charop[2]; intb; scanf ("%s%d%d",op,&a,&b); if(op[0]=='Q') printf ("%d\n", query (A, B,1N1));//node starting from 1: ElseUpdate (A, B,1N1); } }}
I Hate It