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神秘的咒语
描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...
随机推荐
- Java最常见的200+面试题及自己梳理的答案--面试必备(一)
昨天在今日头条上看到一份所谓经常面别人的TL梳理的面试题,看着比较完善,但是,没有对应的答案,自己看着研究学习了下,顺带梳理下答案.主要包括以下模块:Java基础.容器.多线程.反射.对象拷贝.Jav ...
- vscode调试typescript
1.记录一个插件:https://www.npmjs.com/package/ts-node # Locally in your project npm install -D ts-node npm ...
- 45.oracle表类型、数据拆分、表分区
不要做一些没有意义的事情,就比如说你要离职并不打算吃回头草,离职理由中完全没有必要说明“领导的水平太渣,人品太差”此类的原因,而是“个人原因”,当然实在不批准辞职另说. oracle表类型 表的类型分 ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
- 【HNOI2019】部分题简要题解
题意懒得写了 LOJ Day 1 T1 鱼 个人做法比较猎奇,如果有哪位大佬会证明能分享一下的话感激不尽. 题解:枚举鱼尾和鱼身的交点D,将所有其他点按照到D的距离排序,距离相同的分一组. 感性的理解 ...
- MySQL的库、表详细操作
本节目录 一.库操作 二.表操作 三.行操作 一.库操作 1.创建数据库 1.1 语法 CREATE DATABASE 数据库名 charset utf8; 1.2 数据库命名规则 可以由字母.数字. ...
- Mac 10.12安装SVN工具SmartSVM 7.6
说明:SVN工具没有最好的,只有用的最顺手的. 下载: (链接: https://pan.baidu.com/s/1dFGqEsT 密码: uyjx)
- Mac下使用PF进行端口转发和防火墙配置(类似Linux的iptables)
在Mac没有iptables这些,替代的软件为PF,命令为pfctl.在早些版本用ipfw(<=10.10),后面改为PF.还有一些可以使用OpenBsd,不过这个不太好用. 网上关于pfctl ...
- TryParse用法
int.Parse()是一种类型转换:表示将数字内容的字符串转为int类型. 如果字符串为空,则抛出ArgumentNullException异常: 如果字符串内容不是数字,则抛出FormatExce ...
- 手机端全局样式表整理(mobile)
@charset "utf-8";/* * filename: global.css * description: 全局样式(包含样式重置,公共常用 ...