BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]
3173: [Tjoi2013]最长上升子序列
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 1613 Solved: 839
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 0 2
Sample Output
1
2
HINT
100%的数据 n<=100000
插入的数字是递增的,也就是说插入数字后不会改变其他元素的dp值
有一个离线做法:用treap动态把序列弄出来然后求lis
http://hzwer.com/6254.html
在线用splay,f表示以当前元素结尾的LIS长度,mx表示他的子树里最大的f
把新插入的元素转到根后,f就是左子树mx+1(不可能有非法的因为递增啊)
注意:
1.别忘哨兵
2.别忘更新size时还要+1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
#define lc t[x].ch[0]
#define rc t[x].ch[1]
#define pa t[x].fa
const int N=1e5+,INF=1e9;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
} int n,k;
struct node{
int ch[],fa,size,v,f,mx;
node():fa(){ch[]=ch[]=;}
}t[N];
int sz,root;
inline int wh(int x){return t[pa].ch[]==x;}
inline void update(int x){
t[x].size=t[lc].size+t[rc].size+;
t[x].mx=max(t[x].f,max(t[lc].mx,t[rc].mx));
}
inline void rotate(int x){
int f=t[x].fa,g=t[f].fa,c=wh(x);
if(g) t[g].ch[wh(f)]=x;t[x].fa=g;
t[f].ch[c]=t[x].ch[c^];t[t[f].ch[c]].fa=f;
t[x].ch[c^]=f;t[f].fa=x;
update(f);update(x);
}
inline void splay(int x,int tar){
for(;t[x].fa!=tar;rotate(x))
if(t[pa].fa!=tar) rotate(wh(x)==wh(pa)?pa:x);
if(tar==) root=x;
}
inline int kth(int k){
int x=root,lsize=;
while(x){
int _=lsize+t[lc].size;
if(_<k&&k<=_+) return x;
else if(k<=_) x=lc;
else lsize=_+,x=rc;
}
return ;
}
inline int nw(int v){
sz++;t[sz].v=v;t[sz].size=;
return sz;
}
inline void Sol(int k,int v){//printf("Sol %d %d\n",k,v);
int f=kth(k+);splay(f,);//puts("hi");
int x=kth(k+);splay(x,f);//printf("ran %d %d\n",f,x);
lc=nw(v);t[lc].fa=x;
update(x);update(f);
splay(sz,);
t[sz].f=t[t[sz].ch[]].mx+;update(sz); //printf("f %d %d %d\n",sz,t[sz].ch[0],t[sz].f);
printf("%d\n",t[sz].mx);
}
int main(){
//freopen("in.txt","r",stdin);
n=read();
root=nw();t[root].ch[]=nw(N);t[sz].fa=root;
for(int i=;i<=n;i++){
k=read();
Sol(k,i);
}
}
BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]的更多相关文章
- BZOJ 3173: [Tjoi2013]最长上升子序列 Splay
一眼切~ 重点是按照 $1$~$n$ 的顺序插入每一个数,这样的话就简单了. #include <cstdio> #include <algorithm> #define N ...
- bzoj 3173: [Tjoi2013]最长上升子序列【dp+线段树】
我也不知道为什么把题看成以插入点为结尾的最长生生子序列--还WA了好几次 先把这个序列最后的样子求出来,具体就是倒着做,用线段树维护点数,最开始所有点都是1,然后线段树上二分找到当前数的位置,把这个点 ...
- BZOJ 3173: [Tjoi2013]最长上升子序列( BST + LIS )
因为是从1~n插入的, 慢插入的对之前的没有影响, 所以我们可以用平衡树维护, 弄出最后的序列然后跑LIS就OK了 O(nlogn) --------------------------------- ...
- BZOJ 3173: [Tjoi2013]最长上升子序列
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1524 Solved: 797[Submit][St ...
- Bzoj 3173: [Tjoi2013]最长上升子序列 平衡树,Treap,二分,树的序遍历
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1183 Solved: 610[Submit][St ...
- bzoj 3173 [Tjoi2013]最长上升子序列 (treap模拟+lis)
[Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2213 Solved: 1119[Submit][Status] ...
- BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告
这个题感觉比较简单,但却比较容易想残.. 我不会用树状数组求这个原排列,于是我只好用线段树...毕竟 Gromah 果弱马. 我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这 ...
- BZOJ 3173: [Tjoi2013]最长上升子序列 (线段树+BIT)
先用线段树预处理出每个数最终的位置.然后用BIT维护最长上升子序列就行了. 用线段树O(nlogn)O(nlogn)O(nlogn)预处理就直接倒着做,每次删去对应位置的数.具体看代码 CODE #i ...
- 3173: [Tjoi2013]最长上升子序列
原题:http://www.lydsy.com/JudgeOnline/problem.php?id=3173 题解:促使我写这题的动力是,为什么百度遍地是Treap,黑人问号??? 这题可以用线段树 ...
随机推荐
- 动态计算rem的js代码
以最小1024尺寸为例: function rem() { var htmlEle = document.documentElement; var winWidth = htmlEle.clientW ...
- MFC中打开一个获取路径的对话框
不废话,上代码 CString m_FileDir; BROWSEINFO bi; ZeroMemory(&bi, sizeof(BROWSEINFO)); bi.hwndOwner = m_ ...
- [国嵌攻略][068][tftp网络协议实现]
IP协议结构 UDP协议结构 TFTP协议结构 TFTP端口 读写请求端口: 69 其他请求端口:1024~65535 主程序 /*********************************** ...
- python来写打飞机
准备用python写一个打飞机的游戏,相信能够写完这个项目,我对python的学习应该也算可以了. 首先,我们要使用python的一个pygame的库来写,这个库的安装比较简单就是普通的pip安装就可 ...
- java中static关键字的继承问题
结论:java中静态属性和静态方法可以被继承,但是没有被重写(overwrite)而是被隐藏. 原因: 1). 静态方法和属性是属于类的,调用的时候直接通过类名.方法名完成对,不需要继承机制及可以调用 ...
- YourPHP笔记
http://blog.sina.com.cn/s/blog_7c54793101016qq1.htm 基础认识: Ø yourphp安装为子目录时不可以以"yourphp"为文 ...
- WinSCP怎么导入filezilla中的站点?
WinSCP是一款优秀的图形界面,远程文件管理工具,其出色的图形化界面与windows完美集成,是运用在windows上与远程服务器安全传输文件的软件之一 工具/原料 winscp 方法/步骤 下载. ...
- Tomcat 源码分析(二)——Request处理全过程
前一篇博客,我总结了Tomcat对于生命周期组件的管理.在了解了容器的启动之后,我们开始剖析它的内部运行机制.今天我们来分析一下Tomcat如何处理Request.Socket作为网络通信的基础也是R ...
- oracle04_plsql
PLSQL:Procedural Language SQL (1) plsql的基本结构(a) declare id constant number(2):=2;--常量定义 name varchar ...
- 注入理解之APC注入
近期学习做了一个各种注入的MFC程序,把一些心得和体会每天分享一些 APC(Asynchronous procedure call)异步程序调用,在NT中,有两种类型的APCs:用户模式和内核模式.用 ...