Problem Description
Given n integers.
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
Input
T in the first line, indicating the case number.
Each case starts with two integers n , m(0 < n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
Output
For each Q, output the answer.
Sample Input
1
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9
Sample Output
1
1
4
2
3
1
2
5
【分析】
单点修改+询问区间连续最长上升序列长度。
经无数次修改后依然花式RE,懵了。
谁能救救我qwqqq,求大神带。
【代码】
//hdu 3308
#include<iostream>
#include<cstdio>
#define fo(i,j,k) for(i=j;i<=k;i++)
#define p 400000
struct node
{
int sum,l,r,len,lans,rans;
}t[4000001];
using namespace std;
int a[1000001];
int n,x,y,L,R;
inline void update(node &now,node &nowl,node &nowr)
{
// if(nowl.l>p || nowl.r>p || nowr.l>p || nowr.r>p) return;
now.sum=nowl.sum+nowr.sum;
now.len=max(nowl.len,nowr.len);
if(a[nowr.l]>a[nowl.r])
now.len=max(now.len,nowl.rans+nowr.lans);
now.lans=nowl.lans,now.rans=nowr.rans;
if(a[nowr.l]>a[nowl.r])
{
if(nowl.len==nowl.r-nowl.l+1)
now.lans=max(now.lans,nowl.len+nowr.lans);
if(nowr.len==nowr.r-nowr.l+1)
now.rans=max(now.rans,nowr.len+nowl.rans);
}
}
inline void build(int num,int l,int r)
{
t[num].l=l,t[num].r=r;
if(l==r)
{
t[num].sum=a[l];
t[num].len=t[num].lans=t[num].rans=1;
return ;
}
// if(num*2>p) return;
build(num*2,l,(l+r)/2);
build(num*2+1,(l+r)/2+1,r);
update(t[num],t[num*2],t[num*2+1]);
}
inline void change(int num,int l,int r)
{
if(l==r && r==x)
{
t[num].sum=a[l];
t[num].len=t[num].lans=t[num].rans=1;
return;
}
// if(num*2>p) return;
int mid=(l+r)/2;
if(x<=mid) change(num*2,l,mid);
if(x>mid) change(num*2+1,mid+1,r);
update(t[num],t[num*2],t[num*2+1]);
}
inline node find(int L,int R,int num)
{
// if(num*2>p) return t[num];
node now,nowl,nowr;
if(L<=t[num].l && t[num].r<=R) return t[num];
int mid=(t[num].l+t[num].r)/2+1;
if(mid<=L) return find(L,R,num*2+1);
else if(mid>R) return find(L,R,num*2);
nowl=find(L,R,num*2);
nowr=find(L,R,num*2+1);
update(now,nowl,nowr);
return now;
}
int main()
{
int i,j,q,T;
char k[15];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&q);
fo(i,1,n) scanf("%d",&a[i]);
build(1,1,n);
while(q--)
{
scanf("%s%d%d",k,&x,&y);
if(k[0]=='U')
{
a[x+1]=y;
change(1,1,n);
}
else
{
if(x>y) swap(x,y);
printf("%d\n",find(x+1,y+1,1).len);
}
}
}
return 0;
}
//poj 3017 Cut the S
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=100005;
int dp[mxn],g[mxn],q[mxn],a[mxn],sum[mxn];
int n,m;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int main()
{
int i,j,k=0;
n=read(),m=read();
fo(i,1,n)
a[i]=read(),sum[i]=sum[i-1]+a[i];
fo(i,1,n)
if(sum[i]>m) break;
--i;
fo(j,1,i)
{
k=max(k,a[j]);
dp[j]=k;
}
int h=1,t=0;
fo(i,i+1,n)
{
while(h<=t && sum[i]-sum[q[h]-1]>m) h++;
dp[i]=dp[q[h]-1]+a[q[h]];
while(h<=t && a[q[t]]<=a[i]) t--;
q[++t]=i;
}
printf("%d\n",dp[n]);
return 0;
}