标签:des style color os 文件 io 2014 for
基础/******************************************************
author : Grant Yuan
time : 2014.7.27
algorithm: 线段树
source : HDU 1754
*******************************************************/
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define MAX 200003
using namespace std;
struct node{
int l;
int r;
int mm;
};
node tree[3*MAX];
int b[MAX];
int n,m,ans;
void init(int n)
{
for(int i=0;i<=3*n;i++)
{
tree[i].l=0;
tree[i].r=0;
tree[i].mm=0;
}
}
void build(int left,int right,int root)
{
tree[root].l=left;
tree[root].r=right;
if(left==right)
{
tree[root].mm=b[left];
return;
}
int mid=(left+right)>>1;
build(left,mid,root*2);
build(mid+1,right,root*2+1);
tree[root].mm=max(tree[root*2].mm,tree[root*2+1].mm);
}
void update(int k,int root,int p)
{
if(tree[root].l==tree[root].r)
{
tree[root].mm=p;
return;
}
int mid=(tree[root].l+tree[root].r)>>1;
if(mid>=k)
update(k,root*2,p);
else
update(k,root*2+1,p);
tree[root].mm=max(tree[root*2].mm,tree[root*2+1].mm);
}
int findMax(int left,int right,int root)
{
if(tree[root].r<left||tree[root].l>right)
return 0;
if(left<=tree[root].l&&right>=tree[root].r)
return tree[root].mm;
else{
int v1=findMax(left,right,root*2);
int v2=findMax(left,right,root*2+1);
return max(v1,v2);
}
}
int main()
{ char c;int a,bb;
while(~scanf("%d%d",&n,&m)){
for(int i=1;i<=n;i++)
scanf("%d",&b[i]);
build(1,n,1);
for(int i=0;i<m;i++)
{
getchar();
scanf("%c",&c);
if(c=='Q'){ans=0;
scanf("%d%d",&a,&bb);
ans=findMax(a,bb,1);
cout<<ans<<endl;
}
else if(c=='U'){
scanf("%d%d",&a,&bb);
update(a,1,bb);
}
}
}
return 0;
}
标签:des style color os 文件 io 2014 for
原文地址:http://blog.csdn.net/yuanchang_best/article/details/38168321