Another LCIS

Time Limit: 1000ms
Memory Limit: 65536KB

This problem will be judged on UESTC. Original ID: 1425
64-bit integer IO format: %lld      Java class name: Main

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:
4
2
1

Source

 
解题:线段树往死里搞
 
 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct node {
int ret,lv,rv,lsum,rsum,lazy;
} tree[maxn<<];
void pushup(int v,int k) {
tree[v].lsum = tree[v<<].lsum;
tree[v].rsum = tree[v<<|].rsum;
tree[v].lv = tree[v<<].lv;
tree[v].rv = tree[v<<|].rv;
if(tree[v].lsum == k - (k>>) && tree[v<<].rv < tree[v<<|].lv)
tree[v].lsum += tree[v<<|].lsum;
if(tree[v].rsum == (k>>) && tree[v<<].rv < tree[v<<|].lv)
tree[v].rsum += tree[v<<].rsum;
tree[v].ret = max(tree[v<<].ret,tree[v<<|].ret);
if(tree[v<<].rv < tree[v<<|].lv)
tree[v].ret = max(tree[v].ret,tree[v<<].rsum + tree[v<<|].lsum);
}
void pushdown(int v,int k) {
if(tree[v].lazy) {
tree[v<<].lazy += tree[v].lazy;
tree[v<<|].lazy += tree[v].lazy;
tree[v<<].lv += tree[v].lazy;
tree[v<<].rv += tree[v].lazy;
tree[v<<|].lv += tree[v].lazy;
tree[v<<|].rv += tree[v].lazy;
tree[v].lazy = ;
}
}
void build(int L,int R,int v) {
tree[v].lazy = ;
if(L == R) {
tree[v].lsum = tree[v].rsum = ;
scanf("%d",&tree[v].rv);
tree[v].lv = tree[v].rv;
tree[v].ret = ;
return;
}
int mid = (L + R)>>;
build(L,mid,v<<);
build(mid+,R,v<<|);
pushup(v,R - L + );
}
void update(int L,int R,int lt,int rt,int val,int v) {
if(lt <= L && rt >= R) {
tree[v].lazy += val;
tree[v].lv += val;
tree[v].rv += val;
return;
}
pushdown(v,R - L + );
int mid = (L + R)>>;
if(lt <= mid) update(L,mid,lt,rt,val,v<<);
if(rt > mid) update(mid+,R,lt,rt,val,v<<|);
pushup(v,R - L + );
}
int query(int L,int R,int lt,int rt,int v) {
if(lt <= L && rt >= R) return tree[v].ret;
pushdown(v,R - L + );
int ret = ,mid = (L + R)>>;
if(lt <= mid) ret = max(ret,query(L,mid,lt,rt,v<<));
if(rt > mid) ret = max(ret,query(mid+,R,lt,rt,v<<|));
if(lt <= mid && rt > mid && tree[v<<].rv < tree[v<<|].lv)
ret = max(ret,min(mid - lt + ,tree[v<<].rsum) + min(rt - mid,tree[v<<|].lsum));
pushup(v,R - L + );
return ret;
}
int main() {
int T,n,m,x,y,val,cs = ;
char op[];
scanf("%d",&T);
while(T--) {
scanf("%d %d",&n,&m);
printf("Case #%d:\n",cs++);
build(,n,);
while(m--) {
scanf("%s%d%d",op,&x,&y);
if(op[] == 'a') {
scanf("%d",&val);
update(,n,x,y,val,);
} else if(op[] == 'q')
printf("%d\n",query(,n,x,y,));
}
}
return ;
}
/*
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 Case #1:
4
2
1
*/

UESTC 360 Another LCIS的更多相关文章

  1. (中等) 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 ...

  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(1425) another LCIS

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

  4. UESTC 1425 Another LCIS

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

  5. uestc 360(区间合并)

    题意:有一个长度为n的序列.然后有两种操作,Q a b是输出区间a b内最长上升子序列的长度.A a b c是把区间a b内全部数字加上c. 题解:用线段树维护区间的最长上升子序列长度,那么一个区间的 ...

  6. uestc Another LCIS

    Another LCIS Time Limit: 1000 ms Memory Limit: 65536 kB Solved: 193 Tried: 2428 Description For a se ...

  7. Three.js制作360度全景图

    这是个基于three.js的插件,预览地址:戳这里 使用方法: 1.这个插件的用法很简单,引入如下2个js <script src="js/three.min.js"> ...

  8. 360安全卫士造成Sharepoint文档库”使用资源管理器打开“异常

           备注:企业用户还是少用360为妙        有客户反馈:部门里的XP SP2环境客户机全部异常,使用资源管理器打开Sharepoint文档库,看到的界面样式很老土,跟本地文件夹不一样 ...

  9. 内核控制Meta标签:让360浏览器默认使用极速模式打开网页(转)

    为了让网站页面不那么臃肿,也懒的理IE了,同时兼顾更多的国内双核浏览器,在网页页头中添加了下面两行Meta控制标签. 1,网页头部加入 <meta name="renderer&quo ...

随机推荐

  1. poj 2513 欧拉回路+并查集推断是否联通+Trie树

    http://poj.org/problem? id=2513 最初看到 第一感觉---map  一看250000的数据量 果断放弃 然后记得曾经看过.trie取代map.尤其当数据量特别大的时候 学 ...

  2. HNU13377:Book Club(DFS)

    Problem description Porto's book club is buzzing with excitement for the annual book exchange event! ...

  3. 【剑指Offer面试题】 九度OJ1516:调整数组顺序使奇数位于偶数前面

    题目链接地址: http://ac.jobdu.com/problem.php?pid=1516 题目1516:调整数组顺序使奇数位于偶数前面 时间限制:1 秒内存限制:128 兆特殊判题:否提交:2 ...

  4. 使用ShareSDK实现第三方授权登录、分享以及获取用户资料效果,项目中包含:源码+效果图+项目结构图

    [Android应用开发详解]第01期:第三方授权认证(一)实现第三方授权登录.分享以及获取用户资料   由于公司项目的需要,要实现在项目中使用第三方授权登录以及分享文字和图片等这样的效果,几经波折, ...

  5. Android sdk版本以及兼容性问题

    Android:minSdkVersion —— 此属性决定你的应用能兼容的最低的系统版本,一盘情况是必须设置此属性. android:targetSdkVersion —— 此属性说明你当前的应用是 ...

  6. bzoj1010: [HNOI2008]玩具装箱toy(DP+斜率优化)

    1010: [HNOI2008]玩具装箱toy 题目:传送门 题解: 很明显的一题动态规划... f[i]表示1~i的最小花费 那么方程也是显而易见的:f[i]=min(f[j]+(sum[i]-su ...

  7. NET下Assembly的加载过程

    NET下Assembly的加载过程 最近在工作中牵涉到了.NET下的一个古老的问题:Assembly的加载过程.虽然网上有很多文章介绍这部分内容,很多文章也是很久以前就已经出现了,但阅读之后发现,并没 ...

  8. CentOS7.4-btrfs管理及使用

    btrfs, B-tree File System, GPL开源文件系统, 支持CoW即读时写入. 核心特性: 多物理卷支持; btrfs可由多个底层磁盘组成 支持RAID mkfs.btrfs 命令 ...

  9. 三维偏序(陌上花开) CDQ分治

    十分巧妙. Code: #include <cstdio> #include <algorithm> #include <cstring> #define setI ...

  10. CMDB学习之六 --客户端请求测试,服务端api优化

    客户端使用agent 请求测试,agent使用的POST 请求,使用requests模块 本地采集,汇报服务端 #!/usr/bin/env python # -*- coding:utf-8 -*- ...