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. redis cluster 的ERR max number of clients reached 问题排查

    早上发现微服务连不上redis cluster了,看来下日志如下 [root@win-jrh378d7scu 7005]# bin/redis-cli -c -h 15.31.213.183 -p 7 ...

  2. mxonline实战5,用户注册的验证码

        github对应地址:验证码好麻烦     一. 安装 配置 1. pip install django-simple-captcha 2. add captcha to the INSTAL ...

  3. javascript获取wx.config内部字段解决微信分享

    转自:http://www.jb51.net/article/80679.htm 专题推荐:js微信开发_脚本之家 http://www.jb51.net/Special/879.htm 背景在微信分 ...

  4. 前端IDE:VSCode + WebStorm

    VSCode 插件安装 官网:Extensions for the Visual Studio family of products: (1)拼接下载链接: https://${publisher}. ...

  5. Jsp入门实战上

    前面讲了servlet入门实践现在开始介绍jsp入门实践,开发环境的搭建请参考我前面的tomcat的文章,jsp入门教程分为上下两部分,第一部分简单讲解:jsp语法的规范,以及三大编译指令,七个动作指 ...

  6. Visual Studio进行负载测试,RIG和负载测试术语- Part II

    对于一个多用户的应用程序,性能是非常重要的.性能不仅是执行的速度,它包括负载和并发方面.Visual Studio是可以用于性能测试的工具之一.Visual Studio Test版或Visual S ...

  7. (JAVA作业)练习:创建一个类名为Fruit;包含实例变量:水果名称,颜色,价格,上市月份,有无种子 10个实例:苹果,香蕉,芭乐,柚子,李子,杨桃,猕猴桃,哈密瓜,葡萄,榴莲; 实现功能:提示用户输入水果品种编号,输出该水果的全部信息。

    class Lei { String name; String color; int price; int date; int num; String zz; void assemble(){ Sys ...

  8. 【笔记】AJAX基础

    [笔记]AJAX基础 Django AJAX  知识储备:JSON 什么是 JSON JSON 是轻量级的文本数据交换格式 JSON 独立于语言和平台.JSON 解析器和 JSON 库支持许多不同的编 ...

  9. abp 依赖注入声明

    public class SchedulerManager : ISingletonDependency { private ILogger logger; public SchedulerManag ...

  10. Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】

    一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...