CF809D Hitchhiking in the Baltic States
CF809D Hitchhiking in the Baltic States
CF809D
长度为n的序列{xi},n<=3e5,范围在(li,ri)之间,求LIS最长是多长
g(i,l)表示前i个数,LIS长度为l,最后一个数最小是多少(就是那个单调栈)
g(i,l)=min(g(i-1,l),xi (if exist j g(j,l-1)<x))
关于l是递增的。
虽然不知道xi是多少,
但是可以直接用(li,ri)进行计算!最后一定存在一种方法还原xi
刚好可以把一个g(i-1,l-1)+1->g(i,l)
整个区间往上平移再往右平移,再再最下面插入一个点。
实现时候,用平衡树,直接区间+1,某位置插入一个点
最后平衡树点数即为答案
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
char ch;x=;bool fl=false;
while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
for(x=numb;isdigit(ch=getchar());x=x*+numb);
(fl==true)&&(x=-x);
}
template<class T>il void output(T x){if(x/)output(x/);putchar(x%+'');}
template<class T>il void ot(T x){if(x<) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');} namespace Miracle{
const int N=3e5+;
int n,l[N],r[N];
int tot;
struct node{
int ls,rs;
int ad;
int val;
int prio;
}t[*N];
int nc(int v){
++tot;t[tot].val=v;t[tot].prio=rand();
t[tot].ad=t[tot].ls=t[tot].rs=;
// cout<<" nc "<<tot<<" : "<<v<<endl;
return tot;
}
void pushdown(int x){
if(x&&t[x].ad){
t[t[x].ls].ad+=t[x].ad;
t[t[x].rs].ad+=t[x].ad;
t[t[x].ls].val+=t[x].ad;
t[t[x].rs].val+=t[x].ad;
t[x].ad=;
}
}
void split(int now,int &x,int &y,int k){//<=k
if(!now){
x=;y=;return;
}
pushdown(now);
if(t[now].val<=k){
x=now;split(t[now].rs,t[x].rs,y,k);
}else{
y=now;split(t[now].ls,x,t[y].ls,k);
}
}
int dele(int x){
pushdown(x);
int rt=x;
if(!t[x].ls) {
// cout<<" delert "<<x<<" "<<t[x].val<<endl;
return t[x].rs;
}
int y=;
while(t[x].ls){
// cout<<" ls "<<x<<" las "<<y<<endl;
pushdown(x);
y=x;
x=t[x].ls;
}
// cout<<" dele "<<x<<" "<<t[x].val<<" "<<t[x].ls<<" "<<t[x].rs<<endl;
t[y].ls=t[x].rs;return rt;
}
int merge(int x,int y){
if(!x||!y) return x+y;
pushdown(x);pushdown(y);
if(t[x].prio<t[y].prio){
t[x].rs=merge(t[x].rs,y);
return x;
}else{
t[y].ls=merge(x,t[y].ls);
return y;
}
}
int ans=;
void fin(int x){
if(!x) return ;
pushdown(x);
++ans;
fin(t[x].ls);
// cout<<" x "<<x<<" : "<<t[x].val<<endl;
fin(t[x].rs);
}
int main(){
srand();
rd(n);
for(reg i=;i<=n;++i){
rd(l[i]);rd(r[i]);
}
int rt=;
for(reg i=;i<=n;++i){
int x,y,p,q;
split(rt,x,y,l[i]-);
split(y,p,q,r[i]-);
t[p].ad++;
t[p].val++;
// if(i==n) {
// // cout<<" qqqq "<<endl;
// fin(q);
// }
q=dele(q);
// if(i==n) {
// // cout<<" qqqq "<<endl;
// fin(q);
// }
rt=merge(merge(merge(x,nc(l[i])),p),q);
// cout<<"finfifn "<<i<<"------------------------"<<endl;
// fin(rt);
}
ans=;
fin(rt);
ot(ans);
return ;
} }
signed main(){
Miracle::main();
return ;
} /*
Author: *Miracle*
*/
CF809D Hitchhiking in the Baltic States的更多相关文章
- CF809D Hitchhiking in the Baltic States LIS、平衡树
传送门 看到最长上升子序列肯定是DP 设\(f_i\)表示计算到当前,长度为\(i\)的最长上升子序列的最后一项的最小值,显然\(f_i\)是一个单调递增的序列. 转移:对于当前计算的元素\(x\), ...
- 【CF809D】Hitchhiking in the Baltic States(Splay,动态规划)
[CF809D]Hitchhiking in the Baltic States(Splay,动态规划) 题面 CF 洛谷 题解 朴素\(dp\):设\(f[i][j]\)表示当前考虑到第\(i\)个 ...
- 【CF809D】Hitchhiking in the Baltic States Splay
[CF809D]Hitchhiking in the Baltic States 题意:给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足$t_1< ...
- 【CF809D】Hitchhiking in the Baltic States
题意: 给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足t1<t2<...<tlent1<t2<...<tlen.最 ...
- Codeforces 809D. Hitchhiking in the Baltic States
Description 给出 \(n\) 个数 \(a_i\),每一个数有一个取值 \([l_i,r_i]\) ,你来确定每一个数,使得 \(LIS\) 最大 题面 Solution 按照平时做法,设 ...
- CodeForces 809D Hitchhiking in the Baltic States(FHQ-Treap)
题意 给你长度为$n$的序列,序列中的每个元素$i$有一个区间限制$[l_i,r_i]$,你从中选出一个子序列,并给它们标号$x_i$,要求满足 $,∀i<j,x_i<x_j$,且$, ∀ ...
- CF 809D Hitchhiking in the Baltic States——splay+dp
题目:http://codeforces.com/contest/809/problem/D 如果值是固定的,新加入一个值,可以让第一个值大于它的那个长度的值等于它. 如今值是一段区间,就对区间内的d ...
- CF 809 D Hitchhiking in the Baltic States —— 思路+DP(LIS)+splay优化
题目:http://codeforces.com/contest/809/problem/D 看题解,抄标程...发现自己连 splay 都快不会写了... 首先,题目就是要得到一个 LIS: 但与一 ...
- Noip前的大抱佛脚----赛前任务
赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...
随机推荐
- HTTP Cookie header 中set-cookie格式
Cookie相关的Http头 有 两个Http头部和Cookie有关:Set-Cookie和Cookie. Set-Cookie由服务器发送,它包含在响应请求的头部中.它用于在客户端创 ...
- python小数据池 is和 == 再谈编码
1. 小数据池, id() 小数据池针对的是: int, str, bool 在py文件中几乎所有的字符串都会缓存. id() 查看变量的内存地址 2. is和==的区别 is 比较的是内存地址 == ...
- 2019-6-5-VisualStudio-开启仅我代码调试
title author date CreateTime categories VisualStudio 开启仅我代码调试 lindexi 2019-06-05 19:29:44 +0800 2019 ...
- @loj - 2196@「SDOI2014」Lis
目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定序列 A,序列中的每一项 Ai 有删除代价 Bi 和附加属性 ...
- python selenium 测试配置信息(URL和浏览器)
config.ini # this is config file, only store browser type and server URL [browserType] #browserName ...
- H3C 分页显示
- 关于==和equals的探索
在我的概念之中,==在对比两个基本数据类型的时候,对比的是两者的值是否相同.而在对比两个引用数据类型的时候,比较的是两者的内存地址是否相同. 而equals方法,我一直认为这个方法是对比两个引用数据类 ...
- codeforces2B.The least round way 题解 动态规划/模拟
题目出处:http://codeforces.com/problemset/problem/2/B 题目描述 给你一个 \(n \times n\) 的二维数组,它包含的元素都是非负整数.你需要寻找一 ...
- oracle等式比较和范围比较
当WHERE子句中有索引列, ORACLE不能合并它们,ORACLE将用范围比较. 举例: DEPTNO上有一个非唯一性索引,EMP_CAT也有一个非唯一性索引. SELECT ENAME FROM ...
- git之本地仓库关联远程仓库
首先新建一个github respository 然后在自己本地新建一个maven项目,里面写点东西 如下图,将自己的项目所在地设置为本地git仓库 将本地仓库与远程关联,首先获取远程仓库的地址,点击 ...