D - Zip-line

#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 主席树 | 离线树状数组的更多相关文章

  1. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  2. 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 ...

  3. Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  4. Codeforces Round #345 (Div. 2) E. Table Compression 并查集

    E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  8. Codeforces Round #345 (Div. 2) D. Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  9. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

随机推荐

  1. jvm容器的关系

    jvm实例,tomcat容器,spring容器,在内存中的关系5 1.一个java项目对应一个jvm 吗? 2.tomcat里面加载多个java项目 ,是不是用了一个jvm? 3.java项目中的sp ...

  2. IIS最大并发连接数

    最大并发连接数 = 队列长度 + 工作线程数 [工作线程数] IIS实际可以第一时间处理的请求数.比如,工作线程数 = 100,一万个连接请求同时涌过来,那么只有100个可以被处理,其余9900个进入 ...

  3. 第4章-Vue.js 交互及实例的生命周期

    一.学习目标 了解实例生命周期的过程 理解钩子函数的作用 掌握Vue.js过滤器的使用方法 (重点) 能够使用网络请求进行前后端交互 (重点.难点) 二.交互的基本概念 2.1.前端和后端的概念 说明 ...

  4. JS自学大全

    JS是从上往下执行的 console.log();输出语句console.warn();错误提示语句 黄色三角形感叹号console.error();错误提示 红色圆Xalert();弹窗docume ...

  5. centos7 网络问题

    1虚拟机网卡设置--网卡设置模式为NET模式(正常情况是可以直接上网的)2“cd /etc/sysconfig/network-scripts/3使用命令“sudo vi ifcfg-ens33”进入 ...

  6. 2017北京国庆刷题Day1 morning

    期望得分:100+100+100=300 实际得分:100+100+70=270 T1位运算1(bit) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK ...

  7. CF760 D Travel Card 简单DP

    link 题意:乘车,有3种票 1.20块坐1站 2.坐90分钟,50块 3.坐1440分钟,120块 现给出到达每个站的时间,问最优策略 思路: 简单DP,限定条件的3个转移方向,取最小的那个就行了 ...

  8. Laravel是怎么实现autoload的?

    用了一阵Laravel后发现很少有include和require,觉得有点奇怪,思考Laravel是怎么完成文件导入的. 其实Laravel依旧还是用include或者require的,只是都写在一个 ...

  9. 《JavaScript 实战》:JavaScript 实现图片切割效果

    很久之前就在一个网站的截取相片的功能中看到这个效果,也叫图片裁剪.图片剪切(设置一下也可以做出放大镜等类似的效果).当时觉得很神奇,碍于水平有限,没做出来.前些日子突然想做一个透镜效果,就突然想到了这 ...

  10. LintCode 539: Move Zeroes

    终于下决心开始刷题了! 选择LintCode而不是LeetCode主要是因为LintCode操作更顺手,希望能够坚持下去. 还是循序渐进吧,数据结构和算法的东西很久没碰都很生疏了,先找找感觉. 这是一 ...