Kuangbin topic seven HDU1754 I Hate It (single point modification maintenance max)

Source: Internet
Author: User
Tags gcd

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 Input

5 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5

Sample Output

5659
After two questions to hone, finally can hand rub! The details need to be noticed.

1#include <iostream>2#include <stdio.h>3#include <math.h>4#include <string.h>5#include <stdlib.h>6#include <string>7#include <vector>8#include <Set>9#include <map>Ten#include <queue> One#include <algorithm> A#include <sstream> -#include <stack> - using namespacestd; the #defineFO freopen ("In.txt", "R", stdin); - #defineRep (i,a,n) for (int i=a;i<n;i++) - #definePer (i,a,n) for (int i=n-1;i>=a;i--) - #definePB Push_back + #defineMP Make_pair - #defineAll (x) (x). Begin (), (x). End () + #defineFi first A #defineSe Second at #defineSZ (x) ((int) (x). Size ()) - #defineDebug (x) cout << "&&" << x << "&&" << Endl; - #defineLowbit (x) (x&-x) - #defineMem (A, B) memset (A, C, sizeof (a)); -typedef vector<int>VI; -typedefLong Longll; intypedef pair<int,int>PII; - Constll mod=1000000007; to Const intINF =0x3f3f3f3f; +ll Powmod (ll A,ll b) {ll res=1; a%=mod; for(; b;b>>=1){if(b&1) Res=res*a%mod;a=a*a%mod;}returnRes;} -ll GCD (ll A,ll b) {returnB?GCD (b,a%b): A;} the //Head *  $ Const intn=200010;Panax Notoginseng intn,m,a[n<<2],maxx[n<<2],pos,val,ans; -  the voidPushup (intRT) { +Maxx[rt]=max (maxx[rt<<1],maxx[rt<<1|1]); A } the  + voidBuildintRtintLintR) { -     if(l==R) { $scanf"%d", &a[l]);//This must be L . $MAXX[RT]=A[L];//Here is the maintenance information of RT -         return; -     } the     intMid= (l+r) >>1; -Build (rt<<1, l,mid);WuyiBuild (rt<<1|1, mid+1, R); the pushup (RT); - } Wu  - voidUpdata (intRtintLintRintPosintval) { About     if(L==R) {//Modify $a[rt]=Val; -maxx[rt]=A[rt]; -         return; -     } A     intMid= (l+r) >>1; +     if(Pos<=mid) Updata (rt<<1, l,mid,pos,val); the     ElseUpdata (rt<<1|1, mid+1, r,pos,val); - pushup (RT); $ } the  the voidQuery (intRtintLintRintLintR) {//Maintain maximum value the     if(l>=l&&r<=r) { theans=Max (Ans,maxx[rt]); -         return; in     } the     intMid= (l+r) >>1; the     if(L<=mid) Query (rt<<1, l,mid,l,r); About     if(R>mid) Query (rt<<1|1, mid+1, r,l,r); the } the  the intMain () { +      while(~SCANF ("%d%d",&n,&m)) { -Build1,1, n); the         Chars[5];Bayi          while(m--) { theans=-1; thescanf"%s%d%d",s,&pos,&val); -             if(s[0]=='Q') { -Query (1,1, n,pos,val); theprintf"%d\n", ans); the}ElseUpdata (1,1, n,pos,val); the         } the     } -}





Kuangbin topic seven HDU1754 I Hate It (single point modification maintenance max)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.