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 ...
随机推荐
- python 面向对象编程语言
- oracle怎么捕获用户登录信息,如SID,IP地址等
可以利用登录触发器,如 CREATE OR REPLACE TRIGGER tr_login_record AFTER logon ON DATABASE DECLARE miUserSid NUMB ...
- 【C++】位运算实现加减乘除
#include<iostream> #include<assert.h> using namespace std; // 位运算实现加减乘除 int myAdd(int nu ...
- 【JZOJ4878】【NOIP2016提高A组集训第10场11.8】时空传送
题目描述 经过旷久的战争,ZMiG和707逐渐培养出了深厚的感♂情.他们逃到了另一块大陆上,决定远离世间的纷争,幸福地生活在一起.钟情707的neither_nor决心要把他们拆散,他要动用手中最大杀 ...
- AtCoder Regular Contest 084 C - Snuke Festival【二分】
C - Snuke Festival ....最后想到了,可是不应该枚举a[],这样要二重循环,而应该枚举b[],这样只需一重循环... #include<iostream> #inclu ...
- jquery解析XML文件实现的省市联动
XML我是直接在网上下载的文件包 拿过来用的 jquery我用的是3.1的 前台页面 <form action="buy.html" method="get&quo ...
- Oracle错误——引发ORA-01843:无效的月份。
问题 引发ORA-01843:无效的月份. 解决 改动client会话日期的语言: ALTER SESSION SET nls_date_language='american';
- AtCoder Beginner Contest 078 C HSI
虽说这是个水题,但是我做了大概有一个小时吧,才找到规律,刚学概率,还不大会做题. 找到规律后,又想了想,才想到推导过程. 思路:想要知道花费的时间,就要知道提交的次数,我在这里是计算的提交次数的期望, ...
- python 列表长度
- 源映射错误:request failed with status 404
源映射错误:request failed with status 404:源映射错误:request failed with status 404