您的位置:首页 > 其它

【HDU】3308 LCIS

2012-05-24 15:50 176 查看
#include<cstdio>
#define MAXN 100010
struct node
{
int left,right,val;
};
int a[MAXN];
node tree[MAXN<<2];
inline int MAX(int x,int y)
{
return x>y?x:y;
}
inline int MIN(int x,int y)
{
return x>y?y:x;
}
inline void PushUp(int mid,int L,int R,int rt)
{
tree[rt].left=tree[rt<<1].left;
tree[rt].right=tree[rt<<1|1].right;
tree[rt].val=MAX(tree[rt<<1].val,tree[rt<<1|1].val);
if(a[mid]<a[mid+1])
{
if(tree[rt].left==mid-L+1)
tree[rt].left+=tree[rt<<1|1].left;
if(tree[rt].right==R-mid)
tree[rt].right+=tree[rt<<1].right;
tree[rt].val=MAX(tree[rt].val,tree[rt<<1].right+tree[rt<<1|1].left);
}
}
void Build(int L,int R,int rt)
{
if(L==R)
{
scanf("%d",&a[L]);
tree[rt].left=tree[rt].val=tree[rt].right=1;
}
else
{
int mid=(L+R)>>1;
Build(L,mid,rt<<1);
Build(mid+1,R,rt<<1|1);
PushUp(mid,L,R,rt);
}
}
void Update(int x,int val,int L,int R,int rt)
{
if(L==R)
a[L]=val;
else
{
int mid=(L+R)>>1;
if(mid>=x)
Update(x,val,L,mid,rt<<1);
else
Update(x,val,mid+1,R,rt<<1|1);
PushUp(mid,L,R,rt);
}
}
int Query(int x,int y,int L,int R,int rt)
{
if(x<=L&&R<=y)
return tree[rt].val;
int mid=(L+R)>>1,ans=0;
if(mid>=x)
ans=MAX(ans,Query(x,y,L,mid,rt<<1));
if(y>mid)
ans=MAX(ans,Query(x,y,mid+1,R,rt<<1|1));
if(a[mid]<a[mid+1])
ans=MAX(ans,MIN(mid-x+1,tree[rt<<1].right)+MIN(y-mid,tree[rt<<1|1].left));
return ans;
}
int main()
{
char ch;
int c,n,m,x,y;
scanf("%d",&c);
while(c--)
{
scanf("%d%d",&n,&m);
Build(1,n,1);
while(m--)
{
scanf(" %c%d%d",&ch,&x,&y);
if(ch=='U')
Update(x+1,y,1,n,1);
else
printf("%d\n",Query(x+1,y+1,1,n,1));
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: