一眼切~

重点是按照 $1$~$n$ 的顺序插入每一个数,这样的话就简单了.

#include <cstdio>
#include <algorithm>
#define N 100004
#define lson t[x].ch[0]
#define rson t[x].ch[1]
#define setIO(s) freopen(s".in","r",stdin) , freopen(s".out","w",stdout)
using namespace std;
int cnt,root,n;
struct Node
{
int ch[2],f,maxv,siz,val;
}t[N];
inline void pushup(int x)
{
t[x].siz=t[lson].siz+t[rson].siz+1;
t[x].maxv=max(t[x].val,max(t[lson].maxv,t[rson].maxv));
}
inline int get(int x) { return t[t[x].f].ch[1]==x; }
inline void rotate(int x)
{
int old=t[x].f,fold=t[old].f,which=get(x);
t[old].ch[which]=t[x].ch[which^1],t[t[old].ch[which]].f=old;
t[x].ch[which^1]=old,t[old].f=x,t[x].f=fold;
if(fold) t[fold].ch[t[fold].ch[1]==old]=x;
pushup(old),pushup(x);
}
inline void splay(int x,int &tar)
{
int u=t[tar].f;
for(int fa;(fa=t[x].f)!=u;rotate(x))
if(t[fa].f!=u)
rotate(get(fa)==get(x)?fa:x);
tar=x;
}
void insert(int &x,int ff,int pos,int v)
{
if(!x)
{
x=++cnt,t[x].f=ff,t[x].val=v,pushup(x);
return;
}
int lsize=t[lson].siz;
if(pos<=lsize+1) insert(lson,x,pos,v);
else insert(rson,x,pos-lsize-1,v);
pushup(x);
}
inline int find(int kth)
{
int x=root;
while(1)
{
if(t[lson].siz+1==kth) return x;
if(t[lson].siz>=kth) x=lson;
else kth-=(t[lson].siz+1), x=rson;
}
}
void debug(int x) {
if(lson) debug(lson);
printf("%d ",t[x].val);
if(rson) debug(rson);
}
int main()
{
int i,j,ans=0;
// setIO("input");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
int k,lst;
scanf("%d",&k);
if(k==0) lst=1;
else if(k==i-1) lst=t[root].maxv+1;
else
{
splay(find(k+1),root);
lst=t[t[root].ch[0]].maxv+1;
}
insert(root,0,k+1,lst), splay(cnt,root);
// printf("%d\n",t[root].val);
printf("%d\n",t[root].maxv);
}
return 0;
}

  

BZOJ 3173: [Tjoi2013]最长上升子序列 Splay的更多相关文章

  1. BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1613  Solved: 839[Submit][St ...

  2. BZOJ 3173: [Tjoi2013]最长上升子序列( BST + LIS )

    因为是从1~n插入的, 慢插入的对之前的没有影响, 所以我们可以用平衡树维护, 弄出最后的序列然后跑LIS就OK了 O(nlogn) --------------------------------- ...

  3. BZOJ 3173: [Tjoi2013]最长上升子序列

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1524  Solved: 797[Submit][St ...

  4. Bzoj 3173: [Tjoi2013]最长上升子序列 平衡树,Treap,二分,树的序遍历

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1183  Solved: 610[Submit][St ...

  5. bzoj 3173 [Tjoi2013]最长上升子序列 (treap模拟+lis)

    [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2213  Solved: 1119[Submit][Status] ...

  6. BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告

    这个题感觉比较简单,但却比较容易想残.. 我不会用树状数组求这个原排列,于是我只好用线段树...毕竟 Gromah 果弱马. 我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这 ...

  7. BZOJ 3173: [Tjoi2013]最长上升子序列 (线段树+BIT)

    先用线段树预处理出每个数最终的位置.然后用BIT维护最长上升子序列就行了. 用线段树O(nlogn)O(nlogn)O(nlogn)预处理就直接倒着做,每次删去对应位置的数.具体看代码 CODE #i ...

  8. bzoj 3173: [Tjoi2013]最长上升子序列【dp+线段树】

    我也不知道为什么把题看成以插入点为结尾的最长生生子序列--还WA了好几次 先把这个序列最后的样子求出来,具体就是倒着做,用线段树维护点数,最开始所有点都是1,然后线段树上二分找到当前数的位置,把这个点 ...

  9. 3173: [Tjoi2013]最长上升子序列

    原题:http://www.lydsy.com/JudgeOnline/problem.php?id=3173 题解:促使我写这题的动力是,为什么百度遍地是Treap,黑人问号??? 这题可以用线段树 ...

随机推荐

  1. SpringBoot 启动失败 Failed to determine a suitable driver class 问题解决方案

    Description: Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no ...

  2. 集合运算 - Java实现集合的交、并、差

    1.使用java的Set实现集合的交.并.差 package com.lfy.Set; import java.util.HashSet; import java.util.Set; /** * 集合 ...

  3. java 8 date time 简单样例

    参考 Java 8 Time Api 使用指南-珍藏限量版 Java 8 中处理日期和时间示例 部分样例 import java.time.temporal.TemporalAdjusters; im ...

  4. POJ - 1815 Friendship (最小点割集)

    (点击此处查看原题) 题目分析 题意:有n个人,编号记为1~n,n个人之间可能有人可以互相联系,如果A能和B联系,那么至少满足这两种情况之一:(1)A知道B的电话(2)A可以和C联系,并且C可以和B联 ...

  5. 打印指针要用%p而不要用%x

    注意: 打印指针要用%p而不要用%x 原因: https://boredzo.org/blog/archives/2007-01-23/please-do-not-use-percent-x-for- ...

  6. C语言No such file or directory错误

    昨天晚上因为这个错误,都没睡好觉 早上六点起来查资料,换了个绝对路径就行了 #include"D:\软工专业\数据结构PPT和作业\实验作业\实验上机\单链表的基本操作\HeadFile.h ...

  7. scrapy爬取猫眼电影排行榜

    做爬虫的人,一定离不开的一个框架就是scrapy框架,写小项目的时候可以用requests模块就能得到结果,但是当爬取的数据量大的时候,就一定要用到框架. 下面先练练手,用scrapy写一个爬取猫眼电 ...

  8. 简单了解journalctl

    journalctl 命令 journalctl是什么以及作用? journalctl 用来查询 systemd-journald 服务收集到的日志.systemd-journald 服务是 syst ...

  9. Vue与Angular以及React的三者之间的区别

    1.与AngularJS的区别 相同点:都支持指令:内置指令和自定义指令:都支持过滤器:内置过滤器和自定义过滤器:都支持双向数据绑定:都不支持低端浏览器. 不同点:AngularJS的学习成本高,比如 ...

  10. 帝国cms 通过文章的id获取信息

    获取栏目id为13下id为46的数据 [e:loop={"select * from phome_ecms_news where classid = 13 and id = 46" ...