uestc Another LCIS
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的更多相关文章
- UESTC 360 Another LCIS
Another LCIS Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on UESTC. Original ...
- 【37.07%】【UESTC 360】Another LCIS
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Status F ...
- (中等) 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 ...
- UESTC 1425 Another LCIS
也是一个求最长连续单调区间的问题,不同于HDU 3308LCIS的是,单点更新变成了区间成段增加,没关系同样的方法可破之.由于是成段更新,所以比更新区间小的区间是最大连续区间长度是不变的,所以更新su ...
- UESTC 360(1425) another LCIS
这道题是CD老OJ上面的一道题,现在在新OJ上的题号是360,开始在VJ上做的提交一直RE(囧).后来才知道OJ移位了. 这道题是一个简单的成段更新+区间合并的线段树的题,1A还让我小激动了一下 这道 ...
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- UESTC 1015 Lweb and pepper --前,后缀最值
题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...
- BestCoder Round #87 1003 LCIS[序列DP]
LCIS Accepts: 109 Submissions: 775 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65 ...
- LCIS(最长公共上升子序列)Vijos1264神秘的咒语
描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...
随机推荐
- LOJ#6048. 「雅礼集训 2017 Day10」数列(线段树)
题面 传送门 题解 我的做法似乎非常复杂啊-- 首先最长上升子序列长度就等于把它反过来再接到前面求一遍,比方说把\(2134\)变成\(43122134\),实际上变化之后的求一个最长上升子序列和方案 ...
- Qt5学习笔记(消息基础)
#include "MyWidget.h" #include <QApplication> #include <QEvent> #include <Q ...
- MySQL数据库密码破解
研究MySQL数据库的加解密方式,在网络攻防过程中具有重要的意义:试想一旦获取了网站一定的权限后,如果能够获取MySQL中保存用户数据,通过解密后,即可通过正常途径来访问数据库:一方面可以直接操作数据 ...
- angular核心原理解析1:angular自启动过程
angularJS的源代码整体上来说是一个自执行函数,在angularJS加载完成后,就会自动执行了. angular源代码中: angular = window.angular || (window ...
- 解决 MySQL 1045错误的三种方法 (转)
连接MySQL数据库时难免会遇到1045错误,主要是因为用户输入的用户名或密码错误被拒绝访问,如果不想重装,需要找回密码或者重置密码. 问题描述: 1045-Access denied for use ...
- Spring中applicationContext.xml详解
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- C++默认实参
某些函数有这样一种形参,在函数的很多次调用中它们都被赋予一个相同的值,此时,我们把这个反复出现的值称为函数的默认实参.调用含有默认实参的函数时,可以包含该实参,也可以省略该实参. 例如定义一个函数sc ...
- 南昌网络赛 I. Max answer (单调栈 + 线段树)
https://nanti.jisuanke.com/t/38228 题意给你一个序列,对于每个连续子区间,有一个价值,等与这个区间和×区间最小值,求所有子区间的最大价值是多少. 分析:我们先用单调栈 ...
- (一)Audio子系统之AudioRecord.getMinBufferSize
在文章<基于Allwinner的Audio子系统分析(Android-5.1)>中已经介绍了Audio的系统架构以及应用层调用的流程,接下来,继续分析AudioRecorder方法中的ge ...
- Ubuntu里面vi编辑器在编辑文本时 如何在所有行行首或行尾插入字符
例如:我这里是在每一行行首插入new :%s/^/new 在20,50行首插入new :20,50s/^/new 在每一行行尾插入@@ :%s/$/@@ 在20到50行行尾插入## :20,50s/$ ...