Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
Submit 
Status

For a sequence S1,S2,⋯,SNS1,S2,⋯,SN,
and a pair of integers (i,j)(i,j),
if 1≤i≤j≤N1≤i≤j≤N and Si<Si+1<Si+2<⋯<Sj−1<SjSi<Si+1<Si+2<⋯<Sj−1<Sj,
then the sequence Si,Si+1,⋯,SjSi,Si+1,⋯,Sj is
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 TT,
which stands for the number of test cases you need to solve.

Every test case begins with two integers NN, QQ,
where NN is
the size of the sequence, and QQ is
the number of queries. S1,S2,⋯,SNS1,S2,⋯,SN are
specified on the next line, and then QQqueries
follow. Every query begins with a character a or qa is
followed by three integers LL, RR, VV,
meaning that add VV to
members in the interval [L,R][L,R] (including LL, RR),
and q is followed by two integers LL, RR,
meaning that you should output the length of the LCIS of interval [L,R][L,R].

T≤10T≤10;

1≤N,Q≤1000001≤N,Q≤100000;

1≤L≤R≤N1≤L≤R≤N;

−10000≤S1,S2,⋯,SN,V≤10000−10000≤S1,S2,⋯,SN,V≤10000.

Output

For every test case, you should output Case
#k:
 on a single line first, where kk indicates
the case number and starts at 11.
Then for every q query, output the answer on a single line. See sample
for more details.

Sample input and output

Sample Input Sample Output
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

Source

The 9th UESTC Programming Contest Preliminary

【题解】

给你一个初始序列。

然后会不定期的问你这个序列在l..r的区间内最长(严格)上升子序列的长度。

但是还没完。这个序列是会发生改变的。

会定期把区间内的某一段同时递增或减少一个值。

要用线段树来解决。

但是线段树的域应该记录什么呢?

可以这样想。

一个区间内的最长上升子序列。要么整个全部在区间的左半部分。要么整个全部在区间的右半部分。

对不对??

傻逼

还有一种情况呢!

那就是横跨了中间这个域。一部分在左半部分一部分在右半部分。

是不是和hotel那题很像?

用llong[rt],rlong[rt]分别表示起点在(rt节点表示的区间的)左端点和终点在(rt节点表示的区间的)右端点的最长上升子序列的长度。

然后maxlong[rt]表示整个区间内不管在哪里的最长上升子序列的长度。

然后可以想象一下

如果rt的左儿子(x)和右儿子(y)他们满足

x的最右半那个元素<y的最左边那个元素。

那么就可以串成一个rlong[rt<<1]+llong[rt<<1|1]了。这就是横跨的情况了。

根据这个思路。我们还要在线段树的域上加上两个标志,分别记录这个节点表示的区间的最左边的那个元素和最右边的那个元素。

maxlong[rt] = max{maxlong[rt<<1],maxlong[rt<<|1]}

if (rnum[rt<<1]<lnum[rt<<1|1])

maxlong[rt] = max{maxlong,rlong[rt<<1]+llong[rt<<1|1]};

然后就是询问的一些繁琐的事情了。看代码吧。

【代码】

#include <cstdio>
#include <algorithm>
#define lson begin,m,rt<<1
#define rson m+1,end,rt<<1|1 using namespace std; const int MAXN = 100100; int n, m;
int maxlong[MAXN*4],llong[MAXN * 4],rlong[MAXN*4],rnum[MAXN*4],lnum[MAXN*4];
int lazy_tag[MAXN * 4]; void push_up(int rt,int len)//push_up会繁琐一些。
{
bool flag = rnum[rt << 1] < lnum[rt << 1 | 1];
maxlong[rt] = max(maxlong[rt<<1], maxlong[rt<<1|1]);
if (flag)
maxlong[rt] = max(maxlong[rt], rlong[rt << 1] + llong[rt << 1 | 1]);
llong[rt] = llong[rt << 1];//左儿子的最左边那段
if (llong[rt] == (len - (len >> 1)) && flag)//如果整个左儿子都递增 且flag(自己看是什么)
llong[rt] += llong[rt << 1 | 1];//那么就可以加上右儿子的左边部分。
rlong[rt] = rlong[rt << 1 | 1];
if (rlong[rt] == (len >> 1) && flag)
rlong[rt] += rlong[rt << 1];
lnum[rt] = lnum[rt << 1];
rnum[rt] = rnum[rt << 1 | 1];
} void build(int begin, int end, int rt) //建树顺便输入
{
maxlong[rt] = llong[rt] = rlong[rt] = lazy_tag[rt] = 0;
if (begin == end)
{
int x;
scanf("%d", &x);
llong[rt] = rlong[rt] = maxlong[rt] = 1;
rnum[rt] = lnum[rt] = x;
return;
}
int m = (begin + end) >> 1;
build(lson);
build(rson);
push_up(rt,end-begin+1);
} void input_data()
{
scanf("%d%d", &n, &m);
build(1, n, 1);
} void push_down(int rt)//处理懒惰标记
{
if (lazy_tag[rt] != 0)
{
lazy_tag[rt << 1] += lazy_tag[rt];
lazy_tag[rt << 1 | 1] += lazy_tag[rt];
lnum[rt << 1] += lazy_tag[rt];
rnum[rt << 1] += lazy_tag[rt];
lnum[rt << 1 | 1] += lazy_tag[rt];
rnum[rt << 1 | 1] += lazy_tag[rt];
lazy_tag[rt] = 0;
}
} void up_data(int l, int r, int num, int begin, int end, int rt)
{
if (l <= begin && end <= r)
{//递增的时候最长上升序列不会变。因为是一整段同时递增
lazy_tag[rt] += num;
lnum[rt] += num;
rnum[rt] += num;
return;
}
push_down(rt);
int m = (begin + end) >> 1;
if (l <= m)
up_data(l, r, num, lson);
if (m < r)
up_data(l, r, num, rson);
push_up(rt, end - begin + 1);
} int query(int l, int r, int begin, int end, int rt)//询问也有点复杂
{
if (l <= begin && end <= r)
return maxlong[rt];
push_down(rt);
int m = (begin + end) >> 1;
int temp = 0;
bool flag1 = false, flag2 = false;
if (l <= m)
{
temp = max(temp, query(l, r, lson));
flag1 = true;
}
if (m < r)
{
temp = max(temp, query(l, r, rson));
flag2 = true;
}
if (flag1 && flag2 && rnum[rt << 1] < lnum[rt << 1 | 1]) //如果有左半部分、右半部分。且能够串起来
{
int left = min(m - l + 1, rlong[rt << 1]);//不能超过询问的区间长度
int right = min(r - m, llong[rt << 1 | 1]);
temp = max(temp, left + right);//加起来
}
return temp;
} void output_ans()
{
for (int i = 1; i <= m; i++)
{
char op[5];
int x, y, z;
scanf("%s", op);
if (op[0] == 'a')
{
scanf("%d%d%d", &x, &y, &z);
up_data(x, y, z,1, n, 1);
}
else
if (op[0] == 'q')
{
scanf("%d%d", &x, &y);
printf("%d\n", query(x, y, 1, n, 1));
}
}
} int main()
{
//freopen("F:\\rush.txt", "r", stdin);
//freopen("F:\\rush_out.txt", "w", stdout);
int t;
scanf("%d", &t);
for (int ii = 1; ii <= t; ii++)
{
printf("Case #%d:\n",ii);
input_data();
output_ans();
}
return 0;
}

【37.07%】【UESTC 360】Another LCIS的更多相关文章

  1. 【黑金教程笔记之008】【建模篇】【Lab 07 数码管电路驱动】—笔记

    实验七的目的是设计实现最大为99数字在2个数码管上.采用同步动态扫描.即行信号和列信号同步扫描.这里数码管是共阳极的.选择端口也是共阳极的. 模块: /************************ ...

  2. 【Android开发VR实战】二.播放360&#176;全景视频

    转载请注明出处:http://blog.csdn.net/linglongxin24/article/details/53924006 本文出自[DylanAndroid的博客] [Android开发 ...

  3. 【西祠日志】【07】努力努力,找资料,思考,怎么做asp图片上传

    [西祠日志][07]努力努力,找资料.思考.怎么做asp图片上传  (2015.07.23周四) 今天忘了带本子.直接写在书上了笔记,晚点还是夹在本子里. 学了这么久的web应用,一直都没时间去做一点 ...

  4. 【面试】【Spring常见问题总结】【07】

    [常见面试问题总结文件夹>>>] 61.Spring IoC容器的依赖有两层含义: Bean依赖容器:也就是说Bean要依赖于容器,这里的依赖是指容器负责创建Bean并管理Bean的 ...

  5. 【2018.07.30】(广度优先搜索算法/队列)学习BFS算法小记

    一些BFS参考的博客: https://blog.csdn.net/ldx19980108/article/details/78641127 https://blog.csdn.net/u011437 ...

  6. 【docker-compose】使用docker-compose部署运行spring boot+mysql 【处理容器的时区问题】【详解】【福利:使用docker-compose构建 wordpress+mysql】

    ==================================================================================================== ...

  7. 【实战Java高并发程序设计 3】带有时间戳的对象引用:AtomicStampedReference

    [实战Java高并发程序设计 1]Java中的指针:Unsafe类 [实战Java高并发程序设计 2]无锁的对象引用:AtomicReference AtomicReference无法解决上述问题的根 ...

  8. 【更新】【封装必备】封装辅助 - 清理&优化工具 For Win7(IT天空会员专版)

    https://www.itsk.com/thread-353560-1-4.html nqawen 发表于 2015-7-9 17:26:37   本帖最后由 Amz 于 2015-11-25 10 ...

  9. 【剑指Offer学习】【全部面试题汇总】

    剑指Offer学习 剑指Offer这本书已经学习完了.从中也学习到了不少的东西,如今做一个总的文件夹.供自已和大家一起參考.学如逆水行舟.不进则退.仅仅有不断地学习才干跟上时候.跟得上技术的潮流! 全 ...

随机推荐

  1. ArcGIS Engine 线段绘制

    转自ArcGIS Engine 线段绘制研究 基本步骤 构建形状 1. 创建 IPoint IPoint m_Point = new PointClass(); m_Point.PutCoords(x ...

  2. AutoCAD 出现“安全系统(软件锁许可管理器)不起作用或未正确安装”的解决方法

    感谢高飞鸟提供解决方案.当AutoCAD或自动桌子公司的其它产品在启动过程中突然停电或其它原因造成操作系统重启时,可能会造成这些产品的许可出错而无法再运行.一般出错后第一次进入时,会提示你“产品需要激 ...

  3. 题目1205:N阶楼梯上楼问题(2008年华中科技大学计算机保研机试真题:递推求解)

    题目1205:N阶楼梯上楼问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2447 解决:927 题目描写叙述: N阶楼梯上楼问题:一次能够走两阶或一阶,问有多少种上楼方式. (要求 ...

  4. UVA 11557 - Code Theft (KMP + HASH)

    UVA 11557 - Code Theft 题目链接 题意:给定一些代码文本.然后在给定一个现有文本,找出这个现有文本和前面代码文本,反复连续行最多的这些文本 思路:把每一行hash成一个值.然后对 ...

  5. arukas 的 Endpoint

    arukas 的 Endpoint 什么是端点 What is Endpoint arukas.io 的实例几乎每周都自动重新启动,当实例重新启动时,其端口会更改.IP地址和端口的平均寿命是一周,有时 ...

  6. 40.【IntelliJ IDEA】使用idea解决新建jsp文件而找不到jsp文件模版的新建选项

    转自:https://www.cnblogs.com/sxdcgaq8080/p/7676294.html 使用idea解决新建jsp文件而找不到jsp文件模版的新建选项,这样每次创建一个新的jsp文 ...

  7. JQuery操作数组函数 push(),pop(),unshift(),shift()

    1.array.push() :在数组尾部添加新的元素,并返回新的数组长度. 2.array.unshift() :在数组头部添加新的元素,并返回新的数组长度.[听说IE浏览器不支持] 3.array ...

  8. [D3] Reuse Transitions in D3 v4

    D3 transitions start executing as soon as they’re created, and they’re destroyed once they end. This ...

  9. 无状态会话bean(1)---定义

    无状态会话bean用于完毕在单个方法的生命周期内的操作.无状态bean能够实现很多业务操作,可是每一个方法都不能假定不论什么其它的方法会在它之前调用.后半句的意思是如今的你可能不是刚才的你.明天的你可 ...

  10. ASM学习笔记--ASM 4 user guide 第二章要点翻译总结

    参考:ASM 4 user guide 第一部分 core API 第二章  类 2.1.1概观 编译后的类包括: l  一个描述部分:包括修饰语(比如public或private).名字.父类.接口 ...