这让很多学生很反感。
不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。
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]
功能都是线段树很基础的操作,刚开始错误真的很多,而且也很难找有没有。。。。。
#if 0
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
#define lson l,m,id*2
#define rson m+1,r,id*2+1
const int MAXN=230000;
int maxx[MAXN*4]; //
void pushup(int id)
{
maxx[id]=max(maxx[id*2],maxx[id*2+1]);
}
void build(int l,int r,int id)
{
if(l==r)
{
scanf("%d",&maxx[id]);
return;
}
int m=(l+r)/2;
build(lson);
build(rson);
pushup(id);
}
void update(int p,int val,int l,int r,int id)
{
if(l==r)
{
maxx[id]=val;
return;
}
int m=(l+r)/2;
if(p<=m)
update(p,val,lson);
else
update(p,val,rson);
pushup(id);
}
int query(int L,int R,int l,int r,int id)
{
if(L<=l&&R>=r)
{
return maxx[id];
}
int m=(r+l)/2;
int ret=0;
if(L<=m)
{
ret=max(ret,query(L,R,lson));
}
if(R>m)
ret=max(ret,query(L,R,rson));
return ret;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(1,n,1);
while(m--)
{
char s[3];
int a,b;
scanf("%s%d%d",s,&a,&b);
if(s[0]=='Q')
printf("%d\n",query(a,b,1,n,1));
else
update(a,b,1,n,1);
}
}
}
#endif
2285



被折叠的 条评论
为什么被折叠?



