http://acm.hdu.edu.cn/showproblem.php?pid=1754
I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 49750 Accepted Submission (s): 19544
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 Update a certain point in the interval and find the maximum value
#include <stdio.h>#include<string.h>#include<math.h>#include<algorithm>#defineN 200010#defineLson root<<1, L, Tree[root]. Mid ()#defineRson root<<1|1, Tree[root]. Mid () + 1, Rusing namespacestd;structtree{intL, R, Max; intMid () {return(L + R)/2; }}tree[n*4];intAl[n];voidBuild (intRootintLintR) {Tree[root]. L= L, Tree[root]. R =R; if(L = =R) {Tree[root]. Max=Al[l]; return ; } Build (Lson); Build (Rson); Tree[root]. Max= Max (tree[root<<1]. Max, tree[root<<1|1]. Max);}voidUpdate (intRootintKinte) { if(Tree[root]. L = =Tree[root]. R) {Tree[root]. Max=e; return ; } if(k <=Tree[root]. Mid ()) Update (Root<<1, K, E); ElseUpdate (Root<<1|1, K, E); Tree[root]. Max= Max (tree[root<<1]. Max, tree[root<<1|1]. MAX);//Update the k point, but also to update the maximum value of the node, the maximum value of the previous interval node to the left and right two interval node maximum}intQuery (intRootintLintR) { if(Tree[root]. L = = L && tree[root]. R = =R)returnTree[root]. Max; if(R <=Tree[root]. Mid ())returnQuery (root<<1, L, R); Else if(L >Tree[root]. Mid ())returnQuery (root<<1|1, L, R); Else returnMax (Query (Lson), query (Rson));}intMain () {intN, M, a, B, I; Chars[Ten]; while(~SCANF ("%d%d", &n, &m)) { for(i =1; I <= N; i++) scanf ("%d", &Al[i]); Build (1,1, N); while(m--) {scanf ("%s%d%d", S, &a, &b); if(s[0] =='U') Update (1, A, b); Elseprintf ("%d\n", Query (1, A, b)); } } return 0;}/*2 3 4 5 6 7 8 9U 6 8Q 1 6*/
HDU 1754 I Hate It