标签:hdu 1754 i hate it 线段树 单点更新
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 9HintHuge input,the C function scanf() will work better than cin
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define N 200010
#define Mod 10000007
#define lson l,mid,idx<<1
#define rson mid+1,r,idx<<1|1
#define lc idx<<1
#define rc idx<<1|1
const double EPS = 1e-11;
const double PI = acos ( -1.0 );
const double E = 2.718281828;
typedef long long ll;
const int INF = 1000010;
using namespace std;
int tree[N<<2];
int m,n;
void push_up(int idx)
{
tree[idx]=max(tree[lc],tree[rc]);
}
void build(int l,int r,int idx)
{
if(l==r)
{
scanf("%d",&tree[idx]);
return;
}
int mid=(l+r)>>1;
build(lson);
build(rson);
push_up(idx);
}
void update(int l,int r,int idx,int x,int k)
{
if(l==r)
{
tree[idx]=k;
return ;
}
int mid=(l+r)>>1;
if(x<=mid)
update(lson,x,k);
if(x>mid)
update(rson,x,k);
push_up(idx);
}
int query(int l,int r,int idx,int x,int y)
{
if(x<=l&&y>=r)
return tree[idx];
int mid=(l+r)>>1;
int s=-1;
if(x<=mid)
s=max(s,query(lson,x,y));
if(y>mid)
s=max(s,query(rson,x,y));
return s;
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
build(1,n,1);
char s[2];
int x,y;
while(m--)
{
scanf("%s%d%d",s,&x,&y);
if(s[0]=='U')
update(1,n,1,x,y);
else
printf("%d\n",query(1,n,1,x,y));
}
}
return 0;
}
标签:hdu 1754 i hate it 线段树 单点更新
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/42495763