容易发现如果求出最后的序列,只要算一下LIS就好了。序列用平衡树随便搞一下,这里种一棵splay。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 100010
int n,tree[N],cnt=;
struct data
{
int x,f;
bool operator <(const data&a) const
{
return x<a.x;
}
}a[N];
namespace Splay
{
struct data{int fa,ch[],s;}tree[N];
int root=;
int whichson(int k){return tree[tree[k].fa].ch[]==k;}
void up(int k){tree[k].s=tree[tree[k].ch[]].s+tree[tree[k].ch[]].s+;}
void move(int k)
{
int fa=tree[k].fa,gf=tree[fa].fa,p=whichson(k);
if (fa) tree[gf].ch[whichson(fa)]=k;tree[k].fa=gf;
tree[fa].ch[p]=tree[k].ch[!p],tree[tree[k].ch[!p]].fa=fa;
tree[k].ch[!p]=fa,tree[fa].fa=k;
up(fa),up(k);
}
void splay(int k)
{
while (tree[k].fa)
{
int fa=tree[k].fa;
if (tree[fa].fa)
if (whichson(fa)^whichson(k)) move(k);
else move(fa);
move(k);
}
root=k;
}
void ins(int &k,int s,int x,int from)
{
if (!k) {k=x,tree[k].s=,tree[k].fa=from;return;}
if (tree[tree[k].ch[]].s>=s) ins(tree[k].ch[],s,x,k);
else ins(tree[k].ch[],s-tree[tree[k].ch[]].s-,x,k);
}
void dfs(int k)
{
if (tree[k].ch[]) dfs(tree[k].ch[]);
a[++cnt].x=k;
if (tree[k].ch[]) dfs(tree[k].ch[]);
}
}
int query(int k){int s=;while (k) s=max(s,tree[k]),k-=k&-k;return s;}
void ins(int k,int x){while (k<=n) tree[k]=max(tree[k],x),k+=k&-k;}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj3173.in","r",stdin);
freopen("bzoj3173.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();
for (int i=;i<=n;i++)
{
int x=read();
Splay::ins(Splay::root,x,i,);Splay::splay(i);
}
Splay::dfs(Splay::root);
for (int i=;i<=n;i++)
a[i].f=query(a[i].x)+,ins(a[i].x,a[i].f);
sort(a+,a+n+);
for (int i=;i<=n;i++) a[i].f=max(a[i].f,a[i-].f),printf("%d\n",a[i].f);
return ;
}

BZOJ3173 TJOI2013最长上升子序列(splay)的更多相关文章

  1. BZOJ3173:[TJOI2013]最长上升子序列(Splay)

    Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...

  2. [BZOJ3173][Tjoi2013]最长上升子序列

    [BZOJ3173][Tjoi2013]最长上升子序列 试题描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上 ...

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

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

  4. bzoj3173[Tjoi2013]最长上升子序列 平衡树+lis

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2253  Solved: 1136[Submit][S ...

  5. bzoj3173: [Tjoi2013]最长上升子序列(树状数组+二分倒推)

    3173: [Tjoi2013]最长上升子序列 题目:传送门 题解:  好题! 怎么说吧...是应该扇死自己...看错了两次题: 每次加一个数的时候,如果当前位置有数了,是要加到那个数的前面,而不是直 ...

  6. BZOJ3173 TJOI2013最长上升子序列(Treap+ZKW线段树)

    传送门 Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input ...

  7. bzoj千题计划316:bzoj3173: [Tjoi2013]最长上升子序列(二分+树状数组)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3173 插入的数是以递增的顺序插入的 这说明如果倒过来考虑,那么从最后一个插入的开始删除,不会对以某 ...

  8. bzoj3173: [Tjoi2013]最长上升子序列(fhqtreap)

    这题用fhqtreap可以在线. fhqtreap上维护以i结尾的最长上升子序列,数字按从小到大加入, 因为前面的数与新加入的数无关, 后面的数比新加入的数小, 所以新加入的数对原序列其他数的值没有影 ...

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

    一眼切~ 重点是按照 $1$~$n$ 的顺序插入每一个数,这样的话就简单了. #include <cstdio> #include <algorithm> #define N ...

随机推荐

  1. 关于selenium的智能等待页面加载的问题

    我们经常会碰到用selenium操作页面上某个元素的时候,需要等待页面加载完成后,才能操作, 否则页面上的元素不存在,会抛出异常. 或者碰到AJAX异步加载,我们需要等待元素加载完成后,才能操作. 首 ...

  2. arduino八段数码管使用

    一:八段数码管的使用 控制要求:0-9的计时数据 实物连接图: 控制代码: //智慧自动化2018.6.11 ;//定义数字接口7 连接a 段数码管 ;// 定义数字接口6 连接b 段数码管 ;// ...

  3. Unity扩展编辑器一

    将Test1脚本挂在摄像机上 ​ 如图展示 ​ 下面我们需要在代码中动态的编辑它,请在你的Project视图中创建一个Editor文件夹,把MyEditor放进Editor文件夹中 ​ 在OnInsp ...

  4. Eclipse各版本分析比较

    Eclipse最初是由IBM公司开发的替代商业软件Visual Age for Java的下一代IDE开发环境,2001年11月贡献给开源社区,现在它由非营利软件供应商联盟Eclipse基金会. Ec ...

  5. sqlplus远程连接oracle

    格式: sqlplus 用户名/密码@192.168.19.189:1521/MYTEST MYTEST 数据库名称

  6. Final发布 -----欢迎来怼团队

    欢迎来怼项目小组—Final发布展示 一.小组成员 队长:田继平 成员:葛美义,王伟东,姜珊,邵朔,阚博文 ,李圆圆 二.文案+美工展示 链接:http://www.cnblogs.com/js201 ...

  7. [buaa-SE-2017]个人作业-期末总结

    个人作业-期末总结 Part1: 阅读作业 在这一部分,首先我将说说我对这次阅读作业中每篇文章的理解,最后结合这次团队项目的经理谈谈自己对软件开发的看法. 1. No Silver Bullet 文章 ...

  8. Java试验四

    北京电子科技学院(BESTI) 实  验  报  告 课程: Java        班级:1352          姓名:朱国庆         学号:20135237 成绩:           ...

  9. 四则运算《《《《SQL出题

    设计思路: 这次要用数据库存储题目,我想到的是用SQL server数据库,用dataGridView控件读取数据. 具体实现: DBCon.cs 1 using System; 2 using Sy ...

  10. VANET

    VANET知识 VANET与普通网络相比,与IOV的区别: VANET中Greedy Routing:基于距离(GPSR):基于速度和角度:基于道路层(TDR): Repair Strategy:Fa ...