容易发现如果求出最后的序列,只要算一下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. Cloud Native Weekly | 华为云抢先发布Redis5.0,红帽宣布收购混合云提供商 NooBaa

    1——华为云抢先发布Redis5.0 2——DigitalOcean K8s服务正式上线 3——红帽宣布收购混合云提供商 NooBaa 4——微软发布多项 Azure Kubernetes 服务更新 ...

  2. 将禅道部署到腾讯云linux 上

    部署环境 :linux(腾讯云),用到了 xshell   FileZilla 使用禅道集成环境lampp直接部署 1.首先下载 lampp j集成环境包.https://sourceforge.ne ...

  3. CentOS 7.X下 -- 配置nginx正向代理支持https

    环境说明: 本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623. ...

  4. 3. 第一个程序Hello, World!

    第一个接口 HelloWorld 本项目所有代码均可在github上下载. 1. 编辑config.py # 基础配置类 import os class Config(object): ROOT = ...

  5. 【坚持】Selenium+Python学习记录 DAY9

    2018/05/29 [来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html) 运算符重载 https://segmentfault ...

  6. Java 快排 排序

    一.快排的一种 ==================== public class myMain { public static void main(String[] args) { int t[] ...

  7. 2019 年软件开发人员必学的编程语言 Top 3

    AI 前线导读:这篇文章将探讨编程语言世界的现在和未来,这些语言让新一代软件开发者成为这个数字世界的关键参与者,他们让这个世界变得更健壮.连接更加紧密和更有意义.开发者要想在 2019 年脱颖而出,这 ...

  8. ossec代理

    代理端 OSSEC有两种代理端:可安装的代理端和哑代理端(免安装).可安装的代理端被安装在主机上,通过OSSEC的加密协议将主机的信息发送到OSSEC服务器.亚代理端则不需在远端主机进行安装.他作为O ...

  9. CentOS赋予一个普通用户root权限

    http://www.linuxidc.com/Linux/2012-07/64530.htm

  10. json转对象

    1,引入依赖 <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib& ...