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的更多相关文章

  1. CF809D Hitchhiking in the Baltic States LIS、平衡树

    传送门 看到最长上升子序列肯定是DP 设\(f_i\)表示计算到当前,长度为\(i\)的最长上升子序列的最后一项的最小值,显然\(f_i\)是一个单调递增的序列. 转移:对于当前计算的元素\(x\), ...

  2. 【CF809D】Hitchhiking in the Baltic States(Splay,动态规划)

    [CF809D]Hitchhiking in the Baltic States(Splay,动态规划) 题面 CF 洛谷 题解 朴素\(dp\):设\(f[i][j]\)表示当前考虑到第\(i\)个 ...

  3. 【CF809D】Hitchhiking in the Baltic States Splay

    [CF809D]Hitchhiking in the Baltic States 题意:给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足$t_1< ...

  4. 【CF809D】Hitchhiking in the Baltic States

    题意: 给你n个区间[li,ri],让你选出从中一个子序列,然后在子序列的每个区间里都选择一个tj,满足t1<t2<...<tlent1<t2<...<tlen.最 ...

  5. Codeforces 809D. Hitchhiking in the Baltic States

    Description 给出 \(n\) 个数 \(a_i\),每一个数有一个取值 \([l_i,r_i]\) ,你来确定每一个数,使得 \(LIS\) 最大 题面 Solution 按照平时做法,设 ...

  6. CodeForces 809D Hitchhiking in the Baltic States(FHQ-Treap)

    题意 给你长度为$n$的序列,序列中的每个元素$i$有一个区间限制$[l_i,r_i]$,你从中选出一个子序列,并给它们标号$x_i$,要求满足 $,∀i<j,x_i<x_j$,且$, ∀ ...

  7. CF 809D Hitchhiking in the Baltic States——splay+dp

    题目:http://codeforces.com/contest/809/problem/D 如果值是固定的,新加入一个值,可以让第一个值大于它的那个长度的值等于它. 如今值是一段区间,就对区间内的d ...

  8. CF 809 D Hitchhiking in the Baltic States —— 思路+DP(LIS)+splay优化

    题目:http://codeforces.com/contest/809/problem/D 看题解,抄标程...发现自己连 splay 都快不会写了... 首先,题目就是要得到一个 LIS: 但与一 ...

  9. Noip前的大抱佛脚----赛前任务

    赛前任务 tags:任务清单 前言 现在xzy太弱了,而且他最近越来越弱了,天天被爆踩,天天被爆踩 题单不会在作业部落发布,所以可(yi)能(ding)会不及时更新 省选前的练习莫名其妙地成为了Noi ...

随机推荐

  1. 错误信息:FATAL: No bootable medium found! System halted.

    一.解决方法 先上1张图,显示的错误信息 再上2张图,幸好在之前安装了XP系统,不然还真不好解决.从图中可以看出WIN-XP和Linux系统安装好之后的差异,Linux的的存储信息上显示“第二通道没有 ...

  2. Servlet身份验证过滤器

    文件:index.html 文件:MyFilter.java 文件:MyServlet.java 文件:web.xml

  3. Java练习 SDUT-4303_简单的复数运算(类和对象)

    简单的复数运算(类和对象) Time Limit: 2000 ms Memory Limit: 65536 KiB Problem Description 设计一个类Complex,用于封装对复数的下 ...

  4. ntelliJ IDEA2017 + tomcat 即改即生效 实现热部署

    1.点击idea中tomcat设置 2.点击deployment查看Deploy at the server startup 中tomcat每次所运行的包是 xxxx:war 还是其他,如果是xxxx ...

  5. POJ-3186_Treats for the Cows

    Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Description FJ has purchased N (1 <= ...

  6. Google 各国地址

    google各国域名大全 香港www.google.com.hk 台湾www.google.com.tw 日本www.google.co.jp 中国www.google.cn 韩国www.google ...

  7. SQLServer一条SQL查出当月的每一天

    from master..spt_values ),,),'2013-02-03')+'-01' as datetime)) 结果: 返回带有年月日的日期 ),),) AS datetime) fro ...

  8. Project Euler Problem 26-Reciprocal cycles

    看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...

  9. oracle函数 round(x[,y])

    [功能]返回四舍五入后的值 [参数]x,y,数字型表达式,如果y不为整数则截取y整数部分,如果y>0则四舍五入为y位小数,如果y小于0则四舍五入到小数点向左第y位. [返回]数字 [示例] se ...

  10. @51nod - 1196/1197/1198@ 字符串的数量

    目录 @description@ @solution@ @part - 1@ @part - 2@ @part - 3@ @accepted code@ @details@ @description@ ...