I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 62840 Accepted Submission (s): 24384
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
Source 2007 Provincial Training Team Practice (6) _linle Session Parse: Segment tree.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 5 structnode{6 intL, R, Val;7 };8Node node[200005<<2];9 Ten voidBuildintVintLintR) One { ANODE[V].L =l; -NODE[V].R =R; - if(NODE[V].L = =NODE[V].R) { thescanf"%d", &node[v].val); - return; - } - intMid = (l+r) >>1; +Build (v<<1, L, mid); -Build (v<<1|1, mid+1, R); +Node[v].val = Max (node[v<<1].val, node[v<<1|1].val); A } at - intQueryintVintLintR) - { - if(NODE[V].L = = L && NODE[V].R = =R) - returnNode[v].val; - intMid = (NODE[V].L+NODE[V].R) >>1; in if(R <=mid) - returnQuery (v<<1, L, R); to Else if(L >mid) + returnQuery (v<<1|1, L, R); - Else the returnMax (Query (v<<1, L, mid), query (v<<1|1, mid+1, R)); * } $ Panax Notoginseng voidUpdateintVintLintRintm) - { the if(NODE[V].L = = L && NODE[V].R = =R) { +Node[v].val =m; A return; the } + intMid = (NODE[V].L+NODE[V].R) >>1; - if(R <=mid) $Update (v<<1, L, R, M); $ Else if(L >mid) -Update (v<<1|1, L, R, M); - Else{ theUpdate (v<<1, L, Mid, m); -Update (v<<1|1, mid+1, R, m);Wuyi } theNode[v].val = Max (node[v<<1].val, node[v<<1|1].val); - } Wu - intMain () About { $ intN, M; - while(~SCANF ("%d%d", &n, &M)) { -Build1,1, N); - Charorder[5]; A intA, B; + while(m--){ thescanf"%s%d%d", order, &a, &B); - if(order[0] =='Q') $printf"%d\n", Query (1, A, B)); the Else theUpdate1, A, A, B); the } the } - return 0; in}
HDU 1754 I Hate It