# I Hate It

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 66074    Accepted Submission(s): 25697

Problem Description

Input

Output

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
Hint
Huge input,the C function scanf() will work better than cin

Author
linle

Source

Recommend
lcy   |   We have carefully selected several similar problems for you:  1698 1542 1394 2795 1540

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 200000+10;
struct node {
int left,right;
int big;
} s[N*4];
int a[N];
void build(int v,int l,int r) {
s[v].left=l;
s[v].right=r;
if(l==r) {
s[v].big=a[l];
return ;
}
int mid=l+r>>1;
build(v<<1,l,mid);
build((v<<1)|1,mid+1,r);
s[v].big=max(s[v<<1].big,s[(v<<1)|1].big);
}
void update(int v,int x,int y) {
int l=s[v].left;
int r=s[v].right;
if(l==x&&r==x) {
s[v].big=max(s[v].big,y);
return ;
}
int mid=l+r>>1;
if(x<=mid) {
update(v<<1,x,y);
} else {
update((v<<1)|1,x,y);
}
s[v].big=max(s[v].big,y);
}
int Query(int v,int x,int y) {
int l=s[v].left;
int r=s[v].right;
if(l==x&&r==y) {
return s[v].big;
}
int mid=l+r>>1;
if(y<=mid) {
Query(v<<1,x,y);
} else if(x>mid) {
Query((v<<1)|1,x,y);
} else {
return max(Query(v<<1,x,mid),Query((v<<1)|1,mid+1,y));
}
}
int main() {
int n,m;
while(scanf("%d%d",&n,&m)!=EOF) {
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
build(1,1,n);
char c[5];
int x,y;
while(m--) {
scanf("%s",c);
scanf("%d%d",&x,&y);
if(c[0]=='U') {
update(1,x,y);
} else {
printf("%d\n",Query(1,x,y));
}
}
}
return 0;
}

07-21 595

03-27 473

08-02 458

07-05 129

07-19 1146

08-09 121

07-16 157

08-12 688

07-01 1072

09-14 6261