【Codeforces809D】Hitchhiking in the Baltic States
来源:互联网 发布:网络直播电视机顶盒 编辑:程序博客网 时间:2024/06/05 17:57
考虑转移时加入一段区间
对于最大的满足
因为
对于最大的满足
显然
所以我们可以通过一颗非旋转
#include <bits/stdc++.h>#define gc getchar()#define ll long long#define N 300009#define inf 0x3f3f3f3f#define rd(x) (rand()%(x))using namespace std;int n,l[N],r[N];struct node{ int size,val,key,add; node *lson,*rson; node(int v) { val=v; key=rd(100000); if (key<=0) key+=100000; lson=rson=NULL; size=1; add=0; }};typedef node * pnode;int read(){ int x=1; char ch; while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1; int s=ch-'0'; while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0'; return s*x;}void down(pnode now){ now->val+=now->add; if (now->lson) now->lson->add+=now->add; if (now->rson) now->rson->add+=now->add; now->add=0;}pnode merge(pnode L,pnode R){ if (!L) return R; if (!R) return L; if (L->key>R->key) { down(L); L->rson=merge(L->rson,R); return L; } else { down(R); R->lson=merge(L,R->lson); return R; }}void split(pnode now,int val,pnode &L,pnode &R){ if (!now) { L=R=NULL; return; } down(now); if (now->val>=val) { split(now->lson,val,L,now->lson); R=now; return; } else { split(now->rson,val,now->rson,R); L=now; return; }}int find_begin(pnode now){ down(now); if (!now->lson) return now->val; return find_begin(now->lson);}int get_Ans(pnode now){ if (!now) return 0; down(now); return get_Ans(now->lson)+get_Ans(now->rson)+(now->val<inf);}pnode root,L,M,R,rest;int main(){ n=read(); for (int i=1;i<=n;i++) l[i]=read(),r[i]=read(); root=new node(0); for (int i=1;i<=n;i++) root=merge(root,new node(i+inf)); for (int i=1;i<=n;i++) { split(root,l[i],L,R); split(R,r[i],M,R); if (M) M->add++; int Min=find_begin(R); split(R,Min+1,rest,R); root=merge(L,new node(l[i])); root=merge(root,M); root=merge(root,R); } printf("%d\n",get_Ans(root)-1); return 0;}
阅读全文
0 0
- 【Codeforces809D】Hitchhiking in the Baltic States
- [DP 平衡树] Codeforces 809D Round #415 (Div. 1) D. Hitchhiking in the Baltic States
- What are the process states in UNIX?
- Emptying the Baltic
- getting a job while studying in the United States
- Thinking in States
- Thinking in States
- Queryable States in ApacheFlink
- Queryable States in ApacheFlink
- states of the thread
- valid states are 'starting running'. the machine is in the 'poweroff' state 的解决
- vagrant up error: Valid states are 'starting, running'. The machine is in the 'poweroff' state 解决
- Emptying the Baltic(类似最短路?)
- 计蒜客 Emptying the Baltic (BFS+Dijkstra)
- Writing Papers in the United States—A Guide for Foreign Students
- two ways to hold the states of a job in ironic
- arcgis catalog 连接sde时出现 Target state not found in the STATES table 错误
- Visual States in WPF 4.0
- 修改spring boot默认的8080端口
- 【NOIP2017提高A组集训10.25】天才绅士少女助手克里斯蒂娜
- 用Java将doc文档转成pdf格式
- ScriptManager.RegisterStartupScript()的使用
- cmd窗口中cd命令的使用
- 【Codeforces809D】Hitchhiking in the Baltic States
- java中list取前几条数据
- 剑指offer 45 翻转单词顺序列
- java BigDecimal相关操作
- test
- nginx 添加 https
- Java第三课:1+2+3+...n<8888的最大正整数n
- 使用 Flow 写更好的 JavaScript 代码
- git入门使用