111人阅读 评论(0)

# 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

HintHuge 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;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：50575次
• 积分：2834
• 等级：
• 排名：第13112名
• 原创：245篇
• 转载：9篇
• 译文：0篇
• 评论：7条
评论排行
最新评论