LCIS

                                                             Time Limit: 6000/2000 MS (Java/Others)    

                                                            Memory Limit: 65536/32768 K (Java/Others)
                                                            Total Submission(s): 5591    Accepted Submission(s): 2443

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
 
Author
shǎ崽
 
题解:开始看错题,以为是最长子序列,GG,
  后知后觉,线段树秒了
///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a))
#define memfy(a) memset(a,-1,sizeof(a))
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b) scanf("%d%d",&a,&b)
#define mod 1000000007
#define inf 1000000001
#define maxn 200000+2
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
struct ss
{
int l,r,v,ans;
int lc,rc;
}tr[maxn<<];
int a[maxn<<],n,q;
void push_up(int k)
{
if(a[tr[k<<].r]<a[tr[k<<|].l])
{
tr[k].ans=max(max(tr[k<<].ans,tr[k<<|].ans),tr[k<<].rc+tr[k<<|].lc);
if(tr[k<<].lc==(tr[k<<].r-tr[k<<].l+))
{
tr[k].lc=tr[k<<].lc+tr[k<<|].lc;
}else tr[k].lc=tr[k<<].lc;
if(tr[k<<|].lc==(tr[k<<|].r-tr[k<<|].l+))
{
tr[k].rc=tr[k<<|].rc+tr[k<<].rc;
}else tr[k].rc=tr[k<<|].rc;
}
else
{
tr[k].ans=max(tr[k<<].ans,tr[k<<|].ans);
tr[k].lc=tr[k<<].lc;
tr[k].rc=tr[k<<|].rc;
}
}
void build(int k,int s,int t)
{
tr[k].l=s;
tr[k].r=t;
if(s==t)
{
tr[k].v=a[s];
tr[k].ans=;
tr[k].lc=;
tr[k].rc=;
return ;
}
int mid=(s+t)>>;
build(k<<,s,mid);
build(k<<|,mid+,t);
push_up(k);
}
void update(int k,int x,int c)
{
if(tr[k].l==x&&tr[k].r==x)
{
tr[k].v=c;
a[x]=c;
return ;
}
int mid=(tr[k].l+tr[k].r)>>;
if(x<=mid)update(k<<,x,c);
else update(k<<|,x,c);
push_up(k);
}
int ask(int k,int s,int t)
{
if(tr[k].l==s&&tr[k].r==t)
{
return tr[k].ans;
}
int mid=(tr[k].l+tr[k].r)>>;
if(t<=mid)return ask(k<<,s,t);
else if(s>mid)return ask(k<<|,s,t);
else {
int ret=;
int A=ask(k<<,s,mid);
int B=ask(k<<|,mid+,t);
ret=max(A,B);
A=min(tr[k<<].rc,mid-s+);
B=min(tr[k<<|].lc,t-mid);
if(a[tr[k<<].r]<a[tr[k<<|].l])
ret=max(A+B,ret);
return ret;
}
}
int main()
{ int T=read();
while(T--)
{
n=read();
q=read();
FOR(i,,n)
{
a[i]=read();
}
build(,,n);
int a,b;
char ch[];
FOR(i,,q)
{
scanf("%s%d%d",ch,&a,&b);
if(ch[]=='Q')
{
printf("%d\n",ask(,a+,b+));
}
else update(,a+,b);
}
}
return ;
}

代码

最新文章

  1. 分配和释放 BSTR 的内存
  2. Spring 4 官方文档学习(十五)CORS支持
  3. 函数参数为int*和int&amp;的区别
  4. (一)问候Spring4
  5. Gdi+实用入门
  6. SSD: Single Shot MultiBox Detector
  7. WordPress防暴力破解:安全插件和用.htpasswd保护WordPress控制面板
  8. Python调用C/C++动态链接库的方法详解
  9. [置顶] Spring中DI设置器注入
  10. BigDecimal加减乘除运算
  11. winform连接oracle时Oracle.DataAccess.dll版本问题
  12. Java集合系列[1]----ArrayList源码分析
  13. Android官方技术文档翻译——Gradle 插件用户指南(4)
  14. Web开发——JavaScript基础(JSON教程)
  15. win7 java环境变量配置
  16. laravel 数据模型方法
  17. Wingdings 2 符号编码对照表
  18. PPPOE数据包转换及SharpPcap应用
  19. java中的数据结构[copy]
  20. SAP查找用户的登录记录

热门文章

  1. python 列表生成式、lower()和upper()的使用
  2. 如何判断页面是在移动端还是PC端打开的呢
  3. [bzoj2806][Ctsc2012]Cheat(后缀自动机(SAM)+二分答案+单调队列优化dp)
  4. Centos6.8 安装mongo3.6以及权限配置和开启外网链接
  5. 零基础入门学习Python(1)--我和Python的第一次亲密接触
  6. quilt-补丁工具
  7. python3.x Day6 多线程
  8. JS 根据参数是否为空进行true|false判断呢
  9. Max Num
  10. Critical Links-UVa796(无向图求桥)