LCIS

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9713    Accepted Submission(s): 4215

Problem Description
Given n integers.
You have two operations:
U A B: replace the Ath number by B. (index counting from 0)
Q A B: output the length of the longest consecutive increasing subsequence (LCIS) in [a, b].
 
Input
T in the first line, indicating the case number.
Each case starts with two integers n , m(0<n,m<=105).
The next line has n integers(0<=val<=105).
The next m lines each has an operation:
U A B(0<=A,n , 0<=B=105)
OR
Q A B(0<=A<=B< n).
 
Output
For each Q, output the answer.
 
Sample Input
1
10 10
7 7 3 3 5 9 9 8 1 8
Q 6 6
U 3 4
Q 0 1
Q 0 5
Q 4 7
Q 3 5
Q 0 2
Q 4 6
U 6 10
Q 0 9
 
Sample Output
1
1
4
2
3
1
2
5
 
题意:求区间连续递增的最大个数,Q是询问区间内最大的LCIS

U是更新节点

 
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + ;
int llen[maxn << ], rlen[maxn << ], len[maxn << ], tree[maxn];
void pushup(int l, int r, int id)
{
int m = (l + r) >> ;
llen[id] = llen[id << ];
rlen[id] = rlen[id << | ];
if (tree[m + ] > tree[m])
{
if (llen[id << ] == m - l + )
llen[id] += llen[id << | ];
if (rlen[id << | ] == r - m)
rlen[id] += rlen[id << ];
len[id] = max(max(len[id << ], len[id << | ]), rlen[id << ] + llen[id << | ]);
}
else
len[id] = max(len[id << ], len[id << | ]);
}
void build(int l, int r, int id)
{
if (l == r)
{
scanf("%d", &tree[l]);
len[id] = llen[id] = rlen[id] = ;
return;
}
int m = (l + r) >> ;
build(l,m,id<<);
build(m+,r,id<<|);
pushup(l, r, id);
}
int query(int ll, int rr, int l, int r, int id)
{
if (ll <= l && r <= rr)
return len[id];
int m = (l + r) >> ;
if (ll <= m && m < rr)
{
int l1 = query(ll, rr, l,m,id<<);
int l2 = query(ll, rr, m+,r,id<<|);
if (tree[m] < tree[m + ])
{
int le = max(ll, m - rlen[id << ] + );
int ri = min(rr, m + llen[id << | ]);
return max(max(l1, l2), ri - le + );
}
return max(l1, l2);
}
else if (rr <= m)
return query(ll, rr, l,m,id<<);
else
return query(ll, rr, m+,r,id<<|);
} void update(int a, int b, int l, int r, int id)
{
if (a == l && a == r)//找到要更新的位置
{
tree[a] = b;
return;
}
int m = (l + r) >> ;
if (m >= a)
update(a, b, l,m,id<<);
else
update(a, b, m+,r,id<<|);
pushup(l, r, id);
}
int main()
{
int t;
scanf("%d\n", &t);
while (t--)
{
int n, m;
scanf("%d%d", &n, &m);
build(, n - , ); while (m--)
{
char c[];
int a, b;
scanf("%s %d %d", c, &a, &b);
if (c[] == 'Q')
printf("%d\n", query(a, b, , n - , ));
else
update(a, b, , n - , );
}
}
return ;
}

最新文章

  1. [转]看懂UML类图
  2. C和指针 第四章 习题
  3. 获取与Url链接相关的信息
  4. WPF ListBox
  5. STM32串口接收不定长数据原理与源程序(转)
  6. 关于学习YYKit的记录
  7. 【ASP.NET Identity系列教程(二)】运用ASP.NET Identity
  8. meteor 为基础,联合 Apollo + React + React-Router
  9. 使用forever管理nodejs应用
  10. [selector1][selector2][selectorN]
  11. C#根据CPU+磁盘标号来注册软件
  12. wpf 查找页面的所有TextBox
  13. sublime text3 针对于前端开发必备的插件
  14. codevs 1746 贪吃的九头龙
  15. 【原创】纯OO:从设计到编码写一个FlappyBird (一)
  16. Table表格横竖线实现Css
  17. Hibernate的generator属性
  18. UWP Windows历史上最漂亮的UWP框架出炉!!!
  19. java keytool
  20. php5.4、5.5、5.6高版本中htmlspecialchars兼容性处理

热门文章

  1. C#中集合接口关系笔记
  2. docker的概念
  3. RabbitMq学习笔记——MingW编译RabbitMQ C
  4. JDBC--调用函数&amp;存错过程
  5. [Codeforces #608 div2]1271C Shawarma Tent
  6. java web开发缓存方案,ehcache和redis哪个更好
  7. C# 篇基础知识6——文件和流
  8. 2017北京网络赛 J Pangu and Stones 区间DP(石子归并)
  9. (十)微信小程序---上传图片chooseImage
  10. Ubuntu操作系统编写zabbix的启动管理脚本