Another LCIS

Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 193 Tried: 2428

Description

For a sequence S1,S2,...,SN, and a pair of integers (i, j), if 1 <= i <= j <= N and Si < Si+1 < Si+2 <...< Sj-1 < Sj, then the sequence Si,Si+1,...,Sj is a CIS (Continuous Increasing Subsequence). The longest CIS of a sequence is called the LCIS (Longest Continuous Increasing Subsequence).In this problem, we will give you a sequence first, and then some “add” operations and some “query” operations. An add operation adds a value to each member in a specified interval. For a query operation, you should output the length of the LCIS of a specified interval.

Input

The first line of the input is an integer T, which stands for the number of test cases you need to solve.Every test case begins with two integers N, Q, where N is the size of the sequence, and Q is the number of queries. S1,S2,...,SN are specified on the next line, and then Q queries follow. Every query begins with a character ‘a’ or ‘q’. ‘a’ is followed by three integers L, R, V, meaning that add V to members in the interval [L, R] (including L, R), and ‘q’ is followed by two integers L, R, meaning that you should output the length of the LCIS of interval [L, R].

T <= 10;

1 <= N, Q <= 100000;

1 <= L <= R <= N;

-10000 <= S1,S2,...,SN, V <= 10000.

Output

For every test case, you should output "Case #k:" on a single line first, where k indicates the case number and starts at 1. Then for every ‘q’ query, output the answer on a single line. See sample for more details.

Sample Input

1

5 6

0 1 2 3 4

q 1 4

a 1 2 -10

a 1 1 -6

a 5 5 -4

q 2 3

q 4 4

Sample Output

Case #1:421

Source

The 9th UESTC Programming Contest Preliminary

 #include<stdio.h>
#define HH 1
struct st
{
int l,r;
int lnum,rnum;
int max;
int lmax,rmax;
int color;
int num;
} f[*];
int date[];
int max(int x,int y)
{
if(x>y)
return x;
else return y;
}
int min(int x,int y)
{
if(x<y)
return x;
else return y;
}
int Max(int x,int y,int z,int t,int b)
{
return max(max(max(x,y),z),max(t,b));
}
void up(struct st *fa,struct st *lll,struct st *rrr)
{
fa->lnum=lll->lnum;
fa->rnum=rrr->rnum;
if(lll->rnum>=rrr->lnum)
{
fa->lmax=lll->lmax;
fa->rmax=rrr->rmax;
fa->max=max(lll->max,rrr->max);
}
else if(lll->rnum<rrr->lnum)
{
fa->lmax=(lll->lmax==(lll->r-lll->l+))? lll->lmax+rrr->lmax:lll->lmax;
fa->rmax=(rrr->rmax==(rrr->r-rrr->l+))? rrr->rmax+lll->rmax:rrr->rmax;
fa->max=Max(fa->lmax,fa->rmax,lll->max,rrr->max,lll->rmax+rrr->lmax);
}
}
void down(int n)
{
if(f[n*].color==HH)
f[n*].num+=f[n].num;
else f[n*].num=f[n].num;
f[n*].lnum+=f[n].num;
f[n*].rnum+=f[n].num; if(f[n*+].color==HH)
f[n*+].num+=f[n].num;
else f[n*+].num=f[n].num;
f[n*+].lnum+=f[n].num;
f[n*+].rnum+=f[n].num; f[n*].color=HH; f[n*+].color=HH; f[n].color=;
f[n].num=;
}
void build(int l,int r,int n)
{
int mid=(l+r)/;
f[n].l=l;
f[n].r=r;
f[n].color=;
f[n].num=;
if(l==r)
{
f[n].lmax=;
f[n].rmax=;
f[n].max=;
f[n].lnum=date[l];
f[n].rnum=date[l];
return ;
}
build(l,mid,n*);
build(mid+,r,n*+);
up(&f[n],&f[n*],&f[n*+]);
}
void update(int l,int r,int num,int n)
{
int mid=(f[n].l+f[n].r)/;
if(f[n].l==l&&f[n].r==r)
{
if(f[n].color==HH)
f[n].num=f[n].num+num;
else f[n].num=num;
f[n].color=HH;
f[n].lnum+=num;
f[n].rnum+=num;
return ;
}
if(f[n].color==HH)
down(n);
if(mid>=r)
update(l,r,num,n*);
else if(mid<l)
update(l,r,num,n*+);
else
{
update(l,mid,num,n*);
update(mid+,r,num,n*+);
}
up(&f[n],&f[n*],&f[n*+]);
}
int query(int l,int r,int n)
{
int mid=(f[n].l+f[n].r)/;
int a=,b=,ans=;
if(f[n].l==l&&f[n].r==r)
{
return f[n].max;
}
if(f[n].color==HH)
down(n);
if(mid>=r)
return query(l,r,n*);
else if(mid<l)
return query(l,r,n*+);
a=query(l,mid,n*);
b=query(mid+,r,n*+);
if(f[n*].rnum>=f[n*+].lnum)
ans=max(a,b);
else if(f[n*].rnum<f[n*+].lnum)
{
ans=max(max(a,b),min(mid-l+,f[n*].rmax)+min(r-mid,f[n*+].lmax));
}
return ans;
}
int main()
{
int i,j,k,n,m,l,r,num,t;
char c[];
while(scanf("%d",&t)>)
{
for(i=; i<=t; i++)
{
scanf("%d%d",&n,&m);
for(j=; j<=n; j++)
scanf("%d",&date[j]);
build(,n,);
printf("Case #%d:\n",i);
getchar();
for(j=; j<=m; j++)
{
scanf("%s",c);
if(c[]=='q')
{
scanf("%d%d",&l,&r);
k=query(l,r,);
printf("%d\n",k);
}
else if(c[]=='a')
{
scanf("%d%d%d",&l,&r,&num);
update(l,r,num,);
}
}
}
}
return ;
}

uestc Another LCIS的更多相关文章

  1. UESTC 360 Another LCIS

    Another LCIS Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on UESTC. Original ...

  2. 【37.07%】【UESTC 360】Another LCIS

    Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  Status F ...

  3. (中等) UESTC 360 Another LCIS ,线段树+区间更新。

    Description: For a sequence S1,S2,⋯,SN, and a pair of integers (i,j), if 1≤i≤j≤N and Si<Si+1<S ...

  4. UESTC 1425 Another LCIS

    也是一个求最长连续单调区间的问题,不同于HDU 3308LCIS的是,单点更新变成了区间成段增加,没关系同样的方法可破之.由于是成段更新,所以比更新区间小的区间是最大连续区间长度是不变的,所以更新su ...

  5. UESTC 360(1425) another LCIS

    这道题是CD老OJ上面的一道题,现在在新OJ上的题号是360,开始在VJ上做的提交一直RE(囧).后来才知道OJ移位了. 这道题是一个简单的成段更新+区间合并的线段树的题,1A还让我小激动了一下 这道 ...

  6. ACM:UESTC - 649 括号配对问题 - stack

      UESTC - 649  括号配对问题 Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu ...

  7. UESTC 1015 Lweb and pepper --前,后缀最值

    题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...

  8. BestCoder Round #87 1003 LCIS[序列DP]

    LCIS  Accepts: 109  Submissions: 775  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 65536/65 ...

  9. LCIS(最长公共上升子序列)Vijos1264神秘的咒语

    描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...

随机推荐

  1. robot framework学习笔记之二———变量

    Robot Framework的变量分为标量, 列表和字典, 分别使用语法格式 ${SCALAR}, @{LIST} 和 &{DICT} 来定义. 此外, 环境变量可以直接使用语法 %{ENV ...

  2. 表格Table宽度设置无效的解决方法

    表格Table宽度设置无效的解决方法 bootstrap中使用table时发现不管用width赋值方式都无法改变table>td的宽度 解决方法: 设置table:table-layout:fi ...

  3. python基础之循环

    一.while循环 如果条件成立(true),重复执行相同操作,条件不符合,跳出循环 while   循环条件: 循环操作 (1)while循环示例 例:输入王晓明5门课程的考试成绩,计算平均成绩 i ...

  4. C#-语言基础+数据类型+运算符

    一.C#语言基础 新建项目:文件→新建→项目→Visual C#(默认.NET Framework 4.5)→控制台应用程序 1.项目结构 (1)项目后缀 .config ——配置文件(存放配置参数文 ...

  5. NPOI设置水平、垂直居中

    C#语法: string fs = "@report.xls";//文件路径 FileStream excelPath = File.Open(@fs, FileMode.Open ...

  6. HDU - 6133 启发式合并

    题意:给出一棵树共\(n\)个顶点,每个顶点有一个权值\(val_i\),你需要对每个节点统计一个最优解 每个节点的解按照一定规则产生:取出该节点的子树下所有的顶点,把顶点任意排序成一个序列,设为\( ...

  7. 【App性能监控】:Android studio环境的搭建(以及遇到个各种坑)

    今天搭建app性能测试环境,使用的是android studio的Android Device Monitor抓取trace日志分析: 1,下载最新的android studio安装,这一步没啥问题: ...

  8. (转)分布式中使用Redis实现Session共享(一)

    上一篇介绍了如何使用nginx+iis部署一个简单的分布式系统,文章结尾留下了几个问题,其中一个是"如何解决多站点下Session共享".这篇文章将会介绍如何使用Redis,下一篇 ...

  9. (转)Python 运算符

    原文:https://blog.csdn.net/liang19890820/article/details/69690954 简述 在 Python 中,运算符是执行算术或逻辑运算的特殊符号,操作的 ...

  10. Hibernate中Query.list()方法报IllegalArgumentException异常

    最近在使用Hibernate开发项目,在写好hql语句,并初始化Query对象,执行Query.list()方法时,应用报IllegalArgumentException异常.经网上查询,现已经基本决 ...