B-i Hate It

Time limit:3000ms Memory limit:32768kb 64bit IO format:%i64d &%i64u

Submit Status Practice HDU 1754

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

For each query operation, output the highest score in one line.

Sample Input

5 6

1 2 3) 4 5

Q 1 5

U 3 6

Q 3 4

Q 4 5

U 2 9

Q 1 5

Sample Output

5

6

5

9

The base problem of the segment tree, the single-point update, the maximum value of the interval

#include <bits/stdc++.h>using namespace std;const int maxn=200011;const int inf=999999999; #define Lson (rt< <1), L,m#define Rson (rt<<1|1), M+1,r#define M ((l+r) >>1) #define for (i,n) for (int i=0;i< (n); i++) Template<class t>inline T Read (t&x) {char C; while ((C=getchar ()) <=32); BOOL Ok=false; if (c== '-') Ok=true,c=getchar (); for (x=0; c>32; C=getchar ()) x=x*10+c-' 0 '; if (OK) x=-x; return x;} Template<class t> inline void Read_ (t&x,t&y) {read (x); Read (y);} Template<class t> inline void Write (T x) {if (x<0) Putchar ('-'), x=-x; if (x<10) putchar (x+ ' 0 '); else write (X/10), Putchar (x%10+ ' 0 ');} Template<class t>inline void Writeln (T x) {write (x); Putchar (' \ n ');} -------IO template------struct node{int maxv; Node () {maxv=0;}} P[maxn<<2];int n;void Build (int rt,int l,int R,int cnt) {if (cnt>=n) return; if (l==r) {read (P[RT].MAXV); return; } Build (Lson,CNT+1); Build (rson,cnt+1); P[rt].maxv=max (P[RT<<1].MAXV,P[RT<<1|1].MAXV);} void update (int rt,int l,int r,int I,int v) {if (l==r) {P[rt].maxv=v;return; } if (i<=m) update (LSON,I,V); else update (RSON,I,V); P[rt].maxv=max (P[RT<<1].MAXV,P[RT<<1|1].MAXV);} int query (int rt,int l,int r,int x,int y) {//printf ("%d%d%d%d%d\n", rt,l,r,x,y); if (l==x&&y==r) {return P[RT].MAXV; } if (y<=m) return query (lson,x,y); else if (x>m) return query (rson,x,y); else return max (query (lson,x,m), query (Rson,m+1,y));} int main () {#ifndef Online_judge freopen ("In.txt", "R", stdin); #endif//Online_judge int m,i,j,k,t; while (~SCANF ("%d%d", &n,&m)) {build (1,1,n,1); Char op[2]; cout<<m<<endl; while (m--) {scanf ("%s", op); int X,y;read_ (x, y); printf ("%s%d%d\n", op,x,y); if (op[0]== ' Q ') {writeln (query (1,1,n,x,y)); } else if (op[0]== ' U ') {update (1,1,n,x,y); }}} return 0;}

B-i Hate It HDU 1754 segment Tree