I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 51763 Accepted Submission (s): 20297
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 6 1 2 3 4 5 Q 1 5U 3 6 q 3 4 Q 4 5U 2 9 Q 1 5
Sample Output5659
HintHuge input,the C function scanf () would work better than CIN
Authorlinle
Source2007 Provincial Training Team Practice (6) _linle session
Recommendlcy | We have carefully selected several similar problems for you:1166 1698 1542 1394 2795 interval single point update, Interval max. (Recursive thought to establish line segment tree)
1#include <cstdio>2#include <cstring>3#include <iostream>4 #defineMax (A, b) a>b?a:b5 using namespacestd;6 Const intMAXN =200020;7 structNode8 {9 intMax, left, right; Ten} TREE[MAXN *3]; One intN, M, NUM[MAXN]; A intBuild (intRootintLeftintRight ) - { - intmid; theTree[root].left =Left ; -Tree[root].right =Right ; - if(left = right)//leaves; - returnTree[root].max =Num[left]; +Mid = (left + right)/2; - intA, B; +A = Build (2*Root, left, mid); Ab = Build (2*root +1, Mid +1, right); at returnTree[root].max =Max (A, b); - } - intUpdate (intRootintPosintval) - { - if(Pos < Tree[root].left | | Tree[root].right < POS)//the point is not in a child segment - returnTree[root].max; in if(pos = = Tree[root].left && pos = = tree[root].right)//leaves; - returnTree[root].max =Val; to intA, B; +A = Update (2*Root, Pos, Val); -b = Update (2*root+1, POS, Val); theTree[root].max =Max (A, b); * returnTree[root].max; $ } Panax Notoginseng intFind (intRootintLeftintRight ) - { the intmid; + if(Tree[root].left > Right | | tree[root].right < left)//no intersecting line segments; A return 0; the if(Tree[root].left >= left && tree[root].right <= right)//a continuous segment is contained within the search interval; + returnTree[root].max; - intA, B; $A = Find (root*2, left, right); $b = Find (root*2+1, left, right); - returnMax (A, b); - } the intMain () - {Wuyi while(~SCANF ("%d%d", &n, &m)) the { - for(inti =1; I <= N; i++) Wuscanf"%d", &num[i]); -Build (1,1, N); About Charstr[Ten];intA, B; $ for(inti =1; I <= m; i++) - { -CIN >> Str >> a >>b; - if(str[0] =='Q') Aprintf"%d\n", Find (1, A, b)); + Else the { -Num[a] =b; $Update (1, A, b); the } the } the } the return 0; -}
1 http://blog.csdn.net/metalseed/article/details/8039326#
Great God link
Hangzhou Electric 1754--i Hate It (line segment tree)