I Hate ItTime
limit:3000MS
Memory Limit:32768KB
64bit IO Format:%i64d &%i64 U SubmitStatusPracticeHDU 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 2 3 4 5Q 1 5U 3 6Q 3 4Q 4 5U 2 9Q 1 5
Sample Output
5659
Hint
#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;const int maxn=210000; int maxv[maxn*4]; #define MID (L+r)/2#define Lson rt*2,l,mid#define rson rt*2+1,mid+1,rvoid pushup (int x) {Maxv[x]=max (M Axv[x*2],maxv[x*2+1]);} void build (int rt,int l,int R) {if (l==r) {scanf ("%d", &maxv[rt]); }else{build (Lson); Build (Rson); Pushup (RT); }}void Update (int rt,int l,int r,int X,int v) {if (l==r) {maxv[rt]=v; return; } if (mid>=x) update (LSON,X,V); else update (RSON,X,V); Pushup (RT);} int query (int rt,int l,int r,int lp,int rp) {if (LP<=L&&R<=RP) {return MAXV[RT]; } int ret=0; if (lp<=mid) {Ret=max (Ret,query (LSON,LP,RP)); } if (Rp>mid) {Ret=max (Ret,query (RSON,LP,RP)); } return ret;} int main () {int n,m; Char tms[5]; while (scanf ("%d%d", &n,&m)!=eof) {memset (maxv,0,sizeof (MAXV)); BuILD (1,1,n); for (int i=0;i<m;i++) {int a,b,ans; scanf ("%s%d%d", tms,&a,&b); if (tms[0]== ' Q ') {ans=query (1,1,n,a,b); printf ("%d\n", ans); }else{Update (1,1,N,A,B); }}} return 0;}
HDU 1754--i Hate It —————— "segment tree single-point substitution, interval-seeking maximum"