容易发现如果求出最后的序列,只要算一下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. django 部署一个简单的博客系统

    转:https://www.cnblogs.com/fnng/p/3737964.html 写的目的, 加深影响,熟悉开发流程, 开发都是练出来的. 环境 python3.5 windows 7 1. ...

  2. python中函数的定义和详细的使用方法

    1. 函数的概念,函数是将具有独立功能的代码块组织成为一个整体,使其具有特殊功能的代码集   2. 函数的作用,使用函数可以加强代码的复用性,提高程序编写的效率   3. 函数的使用,函数必须先创建才 ...

  3. Docker部署MySQL容器

    从仓库下载镜像 sudo docker pull mysql:5.7   创建容器 docker run --name="mysql" \ -p 3306:3306 \ -v /U ...

  4. appium+python+unittest 测试用例的几种加载执行方式

    利用python进行测试时,测试用例的加载方式有2种: 一种是通过unittest.main()来启动所需测试的测试模块:  一种是添加到testsuite集合中再加载所有的被测试对象,而testsu ...

  5. PHP正则表达式匹配俄文字符

    之前弄过匹配中文的 见 http://www.cnblogs.com/toumingbai/p/4688433.html preg_match_all("/([\x{0400}-\x{04F ...

  6. Beta阶段版本控制报告

    版本控制代码及文档要求 在coding.net版本控制; 公开项目,教师.专家.其他同学可以不注册源代码.在此公布git地址. 报告beta阶段2周中,项目的版本控制情况,不包括未在coding.ne ...

  7. Teamproject Week7 --Scrum Meeting #1 2014.10.28

    这是团队的第一次会议,具体议题如下: 1)我们明确了团队成员的职责所需: PM职责:根据项目范围.质量.时间与成本的综合因素的考虑,进行项目的总体规划与阶段计划.  控制项目组各成员的工作进度,即时了 ...

  8. 《JavaScript》字符转义

    escape/unescape encodeURIComponent/decodeURIComponent encodeURI/decodeURI 转义函数会对一些 特殊字符进行转义编码 英文.数字. ...

  9. BloomFilter——大规模数据处理利器(爬虫判重)

    http://www.cnblogs.com/heaad/archive/2011/01/02/1924195.html Bloom Filter是由Bloom在1970年提出的一种多哈希函数映射的快 ...

  10. [图的遍历&多标准] 1087. All Roads Lead to Rome (30)

    1087. All Roads Lead to Rome (30) Indeed there are many different tourist routes from our city to Ro ...