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 ...
随机推荐
- Socket初识2
一.Socket一些概念 sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) 1.1 参数1:Socket Families(地址簇) / ...
- Linux改变用户shell的类型
命令: 改变usr01的类型 # usermod -s /bin/csh usr01
- 课程设计——利用信号量实现生产者-消费者问题(java)
package cn.Douzi.ProductConsume; import java.util.LinkedList; import java.util.Queue; import java.ut ...
- Elasticsearch技术解析与实战(七)Elasticsearch partial update
普通的partial update 1.插入测试数据 PUT /test_index/test_type/10 { "test_field1": "test1" ...
- 不修改代码优化 ASP.NET 网站性能的一些方法
本文将介绍一些方法用于优化ASP.NET网站性能,这些方法都是不需要修改程序代码的.它们主要分为二个方面:1. 利用ASP.NET自身的扩展性进行优化.2. 优化IIS设置. 配置OutputCach ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- 指针A - 签到题(顺序三元组)
给定一个长度为N的数组A=[A1, A2, ... AN],已知其中每个元素Ai的值都只可能是1, 2或者3. 请求出有多少下标三元组(i, j, k)满足1 ≤ i < j < k ≤ ...
- 【洛谷 P4437】 [HNOI/AHOI2018]排列(贪心,堆)
题目链接 如果\(j<=k,a_{p[j]}!=p[k]\)可以理解为如果\(a_{p[j]}=p[k]\),那么\(k\)一定要放在\(j\)前面,也就是\(a_j\)在\(j\)前面. 于是 ...
- DNSLOG在渗透测试中的玩法儿
首先了解一下DNS是啥??? DNS(Domain Name System,域名系统),万维网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读 ...
- tera term通过ttl脚本 自动连接服务器(转自http://www.cnblogs.com/wxb0328/p/teraterm.html)
转自http://www.cnblogs.com/wxb0328/p/teraterm.html 在现在的这个公司一直使用tera term来远程连接服务器,感觉很方便,特别是它的ttl脚本配置的自动 ...