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. vue + ElementUI 关闭对话框清空验证,清除form表单

    前面跟大家提到过 elementUI验证的问题,那么今天就来看看 点击对话框和关闭按钮 怎么清空验证,清空form表单,避免二次点击还会有 验证错误的提示 1.首先在你的对话框 取消按钮 加一个cli ...

  2. Python 魔法方法查询表 -- 总结篇

    据说,Python 的对象天生拥有一些神奇的方法,它们总被双下划线所包围,他们是面向对象的 Python 的一切. 他们是可以给你的类增加魔力的特殊方法,如果你的对象实现(重载)了这些方法中的某一个, ...

  3. 二手前端入门React项目

    个人对ReactJS这门技术比较感兴趣,在基友的帮助下成功创建了一个React标准前端工程,过程中遇到了不少麻烦,今天作为笔记一般记录一下遇到的问题和解决方案. 基础环境 手头一台Mac 使用OSX系 ...

  4. Java初学者的学习路线建议

    java学习这一部分其实也算是今天的重点,这一部分用来回答很多群里的朋友所问过的问题,那就是我你是如何学习Java的,能不能给点建议?今天我是打算来点干货,因此咱们就不说一些学习方法和技巧了,直接来谈 ...

  5. SAE实践——创建新应用开启MySQL服务

    1. 创建SAE应用 当创建完成SAE账户之后,即可创建SAE应用.点击创建新应用按钮,创建一个新的SAE 应用 阅读提示信息,等待五秒,点继续创建. 填写应用信息完成创建.可选择PHP5.3和空应用 ...

  6. (RaspBerry Pi) Python GPIO 基本操作

    目前打算由潛入深慢慢學習RaspBerry Pi, 所以先由最容易下手的Python進入樹莓派的世界 首先要使用 GPIO 需要利用RPI.GPIO package想當然爾必須先安裝 所以先執行下列命 ...

  7. day1: python3.5学习

    1. 基础知识 变量:用于存储信息,方便后面的调用 常量:python中是没有常量这一概念的,若想定义一个常量,需要将变量名大写 举例:name = "Helen"   #定义一个 ...

  8. numpy.argmax()

    numpy.argmax(a, axis=None, out=None) 返回沿轴axis最大值的索引 Parameters: a : array_like                      ...

  9. 【old】Python学习笔记

    上学期看视频记得,也没学到多少,目前打算一边通过<Python学习手册 第四版>提高核心语法(太厚了 噗),一边学习Python Web开发 然后这里的多任务编程和网络编程是暑假学的 5. ...

  10. Zynq-7000 FreeRTOS(一)系统移植配置

    软件版本:VIvado HLx 2018.2 从FreeRTOS的官网中下载源代码: https://www.freertos.org/a00104.html 图:FreeRTOS的官网 上图中,点击 ...