I Hate It
Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 70 Accepted Submission(s) : 24
这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
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
5 6 5 9 [hint]Huge input,the C function scanf() will work better than cin[/hint]
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define lson l,m,rt*2//左子树 父节点rt表示区间[l,r],左子树rt*2表示的区间[l,l+r/2]
#define rson m+1,r,rt*2+1//右子树 父节点rt表示区间[l,r],右子树rt*2+1[l+r/2+1,r]
#define inf 222222*4
int tree[inf];
int max(int a,int b)
{
if(a<b) return b;
return a;
}
void pushup(int rt)
{
tree[rt]=max(tree[rt*2],tree[rt*2+1]);//最大值
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&tree[rt]);
return;
}
int m=(l+r)/2;
build(lson);
build(rson);
pushup(rt);
}
void update(int p,int sc,int l,int r,int rt)//位置 改成这个数
{
if(l==r)
{
tree[rt]=sc;
return;
}
int m=(l+r)/2;
if(p<=m) update(p,sc,lson);
else update(p,sc,rson);
pushup(rt);
}
int query(int ll,int rr,int l,int r,int rt)
{
if(ll<=l&&r<=rr)
return tree[rt];
int m=(l+r)/2;
int ret=0;
if(ll<=m) ret=max(ret,query(ll,rr,lson));
if(rr>m) ret=max(ret,query(ll,rr,rson));
return ret;
}
int main()
{
int n,mm,a,b;
string s;
while(cin>>n>>mm)
{
build(1,n,1);
while(mm--)
{
cin>>s;
scanf("%d%d",&a,&b);
if(s=="Q")
cout<<query(a,b,1,n,1)<<endl;
else
update(a,b,1,n,1);
}
}
}