Codeforces Round #345 (Div. 1) D - Zip-line 带单点修改的LIS 主席树 | 离线树状数组
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int> using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, m, tot, h[N], hs[N], dp[][N], stk[N], cnt[N], LIS;
bool is[N]; struct ChairmanTree {
struct node {
int mx, l, r;
} a[N * ];
int tot, root[N];
void update(int p, int val, int l, int r, int &x, int y) {
x = ++tot; a[x] = a[y];
a[x].mx = max(a[x].mx, val);
if(l == r) return ;
int mid = l + r >> ;
if(p <= mid) update(p, val, l, mid, a[x].l, a[y].l);
else update(p, val, mid + , r, a[x].r, a[y].r);
}
int query(int L, int R, int l, int r, int x) {
if(hs[r] < L || hs[l] > R) return ;
if(hs[l] >= L && hs[r] <= R) return a[x].mx;
int ans = , mid = l + r >> ;
if(L <= hs[mid]) ans = query(L, R, l, mid, a[x].l);
if(R > hs[mid]) ans = max(ans, query(L, R, mid + , r, a[x].r));
return ans;
}
}ct[]; void getLIS() {
memset(stk, inf, sizeof(stk));
for(int i = ; i <= n; i++) {
dp[][i] = lower_bound(stk, stk + N, h[i]) - stk + ;
stk[dp[][i] - ] = h[i];
LIS = max(LIS, dp[][i]);
}
memset(stk, inf, sizeof(stk));
for(int i = n; i >= ; i--) {
dp[][i] = lower_bound(stk, stk + N, -h[i]) - stk + ;
stk[dp[][i] - ] = -h[i];
}
for(int i = ; i <= n; i++) {
if(dp[][i] + dp[][i] == LIS + ) {
is[i] = true;
cnt[dp[][i]]++;
}
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d", &h[i]);
hs[++tot] = h[i];
}
sort(hs + , hs + + tot);
tot = unique(hs + , hs + + tot) - hs - ; for(int i = ; i <= n; i++)
h[i] = lower_bound(hs + , hs + + tot, h[i]) - hs;
getLIS(); for(int i = ; i <= n; i++)
ct[].update(h[i], dp[][i], , tot, ct[].root[i], ct[].root[i-]);
for(int i = n; i >= ; i--)
ct[].update(h[i], dp[][i], , tot, ct[].root[i], ct[].root[i+]); while(m--) {
int a, b;
scanf("%d%d", &a, &b);
int ans = is[a] ? LIS - : LIS;
ans = max(ans, ct[].query(, b - , , tot, ct[].root[a-])
+ ct[].query(b + , inf, , tot, ct[].root[a+]) + );
if(is[a] && cnt[dp[][a]] > ) {
ans = max(ans, LIS);
}
printf("%d\n", ans);
}
return ;
} /*
*/
Codeforces Round #345 (Div. 1) D - Zip-line 带单点修改的LIS 主席树 | 离线树状数组的更多相关文章
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #345 (Div. 1) D. Zip-line 上升子序列 离线 离散化 线段树
D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #345 (Div. 2) E. Table Compression 并查集
E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...
- codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
- Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分
D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
随机推荐
- VC++的debug与release版本
因为在Debug中有ASSERT断言保护,所以要崩溃,而在Release优化中就会删掉ASSERT,所以会出现正常运行. void func() { char b[2]={0}; strc ...
- for程序员:这些你可能遇到的职场难题,我们帮你整理好了答案
“迷茫”是当下青年谈论的最多的词汇之一,无论高矮胖瘦富穷美丑,每个人都有自己独特的难题.造成“迷茫”的原因有很多种,比如生存压力,情感问题,以及困扰着相当一部分人的职场焦虑.今天这篇关于“职场迷茫”的 ...
- "Access restriction: The type BASE64Encoder is not accessible due to restrict"问题解决
问题如题: Eclipse中有一种叫做存取限制的机制,来防止你错误使用那些非共享的API.通常来说,Eclipse做的是对的,因为两点,我们不想要使用非共享API的,而且Eclipse知道什么是共享的 ...
- MyEclipse+Weblogic+Oracle+PLSQL配置注意事项
Weblogic配置详情:<Weblogic安装与配置图文详解>Oracle+PLSQL配置详情:<PL/SQL访问远程Oracle服务器(多种方式)>MyEclipse配置: ...
- bzoj 2453: 维护队列
2453: 维护队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1079 Solved: 503[Submit][Status][Discuss ...
- Codeforces 450B div.2 Jzzhu and Sequences 矩阵快速幂or规律
Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...
- Spring Cloud全家桶主要组件及简要介绍
一.微服务简介 微服务是最近的一两年的时间里是很火的一个概念.感觉不学习一下都快跟不上时代的步伐了,下边做一下简单的总结和介绍. 何为微服务?简而言之,微服务架构风格这种开发方法,是以开发一组小型服务 ...
- 第5堂音频课:发音&词串&自学方法示范
1. 发音怎么练习 我讲解的第5-6节发音课,就像一个有用教练,教你的划水姿势,你学了以后,在床上趴着练练蹬腿,然后,要立刻跳下水去游泳,也就是说,你要去听英语: 请你听一段可可宝贝APP的绘本故事, ...
- 36 - 网络编程-TCP编程
目录 1 概述 2 TCP/IP协议基础 3 TCP编程 3.1 通信流程 3.2 构建服务端 3.3 构建客户端 3.4 常用方法 3.4.1 makefile方法 3.5 socket交互 3.4 ...
- ProxySQL(MGR)部署故障:'sys.gr_member_routing_candidate_status' doesn't exist
ProxySQL(MGR) 故障排查: 故障现象:runtime_mysql_servers节点状态offline_hostgroup(本案例为15) 日志关键信息: [WARNING] Group ...