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
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=10 5)
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
思路:需要对最长递增子序列进行维护,每次一个个找肯定会爆。
AC代码:
#include
#include
using namespace std;
int n,m,num[100010];
struct node
{
int l,r,c;//左右边界和区间长度
int ln,rn;//左右边界的值
int ls,rs,ms;//左右及区间的最长递增序列(LCIS)
}tree[400010];
void up(int k)
{
tree[k].ls=tree[k*2].ls;
tree[k].rs=tree[k*2+1].rs;//更新左右边界值
tree[k].ln=tree[k*2].ln;
tree[k].rn=tree[k*2+1].rn;//更新左右边界LCIS长度
tree[k].ms=max(tree[k*2].ms,tree[k*2+1].ms);//更新区间内LCIS长度
if(tree[k*2].rn=l&&tree[k].r<=r) return tree[k].ms;
int m=(tree[k].l+tree[k].r)/2,ans=0;
if(l<=m)
ans = max(ans,query(l,r,2*k));
if(r>m)
ans=max(ans,query(l,r,2*k+1));
if(tree[k*2].rn>1;
if(t<=mid)
insert(2*i,t,m);
if(t>mid)
insert(2*i+1,t,m);
up(i);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d%*c",&num[i]);
build(1,n,1);
while(m--)
{
getchar();
char c;
int a,b;
scanf("%c %d %d",&c,&a,&b);
//cout<