I Hate It
Time limit:9000/3000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 59023 Accepted Submission (s): 22996
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. To find the maximum number of intervals, the simplest application of segment tree. Http://www.cnblogs.com/TenosDoIt/p/3453089.html
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
Source2007 Provincial Training Team Practice (6) _linle session
Recommendlcy | We have the carefully selected several similar problems for you:1166 1698 1542 1394 2795 to find the maximum number of intervals, the simplest segment tree application problem. Http://www.cnblogs.com/TenosDoIt/p/3453089.html The Great God's explanation blog.
#include <iostream>#include<stdio.h>#include<algorithm>#include<math.h>#defineMax1 2000005intA[max1];using namespacestd;Const intinfinite=-1111111;structsegtreenode{intVal; intAddmark;} Segtree[max1<<1];voidBuildintRootintArr[],intIstartintiend) {Segtree[root].addmark=0; if(istart==iend) Segtree[root].val=Arr[istart]; Else { intMid= (istart+iend)/2; Build (Root*2+1, Arr,istart,mid); Build (Root*2+2, arr,mid+1, iend); Segtree[root].val=max (segtree[root*2+1].val,segtree[root*2+2].val); }}/*void pushdown (int root) {if (segtree[root].addmark!=0) {Segtree[root*2+1].addmark+=segtree[root].addmark; Segtree[root*2+2].addmark+=segtree[root].addmark; Segtree[root*2+1].val+=segtree[root].addmark; Segtree[root*2+2].val+=segtree[root].addmark; segtree[root].addmark=0; }}*/intQueryintRootintNstart,intNend,intQstart,intqend) { if(qstart>nend| | qend<Nstart)returnINFINITE; if(qstart<=nstart&&qend>=nend)returnSegtree[root].val; //pushdown (root); intMid = (nstart+nend)/2; returnMax (Query (root*2+1, nstart,mid,qstart,qend), query (root*2+2, mid+1, Nend,qstart,qend));}/*void Update (int root,int nstart,int nend,int ustart,int uend,int addval) {if (ustart>nend| | Uend<nstart) return; if (ustart<=nstart&&uend>=nend) {segtree[root].addmark+=addval; Segtree[root].val+=addval; Return }//pushdown (root); int mid= (nstart+nend)/2; Update (ROOT*2+1,NSTART,MID,USTART,UEND,ADDVAL); Update (ROOT*2+2,MID+1,NEND,USTART,UEND,ADDVAL); Segtree[root].val=max (Segtree[root*2+1].val,segtree[root*2+2].val);}*/voidUpdateone (intRootintNstart,intNend,intIndexintaddval) { if(nstart==nend) { if(index==nstart) Segtree[root].val=Addval; return; } intMid= (nstart+nend)/2; if(index<=mid) Updateone (root*2+1, Nstart,mid,index,addval); ElseUpdateone (Root*2+2, mid+1, Nend,index,addval); Segtree[root].val=max (segtree[root*2+1].val,segtree[root*2+2].val);}intMain () {intn,m; while(~SCANF ("%d%d",&n,&m)) { for(intI=0; i<n;i++) scanf ("%d",&a[i]); GetChar (); Build (0A0, N-1); //for (int i=0;i<2*n-1;i++)//cout<<segtree[i].val<<endl; Charmov; intP1; intP2; for(intI=0; i<m;i++) {scanf ("%c",&mov); scanf ("%d%d",&p1,&p2); GetChar (); if(mov=='U') {Updateone (0,0, N-1, p1-1, p2); } if(mov=='Q') {printf ("%d\n", Query (0,0, N-1, p1-1, p2-1)); } } } return 0;}
View Code
Here I wa several times, and then enlarged the array 10 times times over, do not know what the reason. If someone is also always tle can try.
HDU 1754 I Hate It