BZOJ3173 TJOI2013最长上升子序列(splay)
容易发现如果求出最后的序列,只要算一下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)的更多相关文章
- BZOJ3173:[TJOI2013]最长上升子序列(Splay)
Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...
- [BZOJ3173][Tjoi2013]最长上升子序列
[BZOJ3173][Tjoi2013]最长上升子序列 试题描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上 ...
- BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1613 Solved: 839[Submit][St ...
- bzoj3173[Tjoi2013]最长上升子序列 平衡树+lis
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2253 Solved: 1136[Submit][S ...
- bzoj3173: [Tjoi2013]最长上升子序列(树状数组+二分倒推)
3173: [Tjoi2013]最长上升子序列 题目:传送门 题解: 好题! 怎么说吧...是应该扇死自己...看错了两次题: 每次加一个数的时候,如果当前位置有数了,是要加到那个数的前面,而不是直 ...
- BZOJ3173 TJOI2013最长上升子序列(Treap+ZKW线段树)
传送门 Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input ...
- bzoj千题计划316:bzoj3173: [Tjoi2013]最长上升子序列(二分+树状数组)
https://www.lydsy.com/JudgeOnline/problem.php?id=3173 插入的数是以递增的顺序插入的 这说明如果倒过来考虑,那么从最后一个插入的开始删除,不会对以某 ...
- bzoj3173: [Tjoi2013]最长上升子序列(fhqtreap)
这题用fhqtreap可以在线. fhqtreap上维护以i结尾的最长上升子序列,数字按从小到大加入, 因为前面的数与新加入的数无关, 后面的数比新加入的数小, 所以新加入的数对原序列其他数的值没有影 ...
- BZOJ 3173: [Tjoi2013]最长上升子序列 Splay
一眼切~ 重点是按照 $1$~$n$ 的顺序插入每一个数,这样的话就简单了. #include <cstdio> #include <algorithm> #define N ...
随机推荐
- AssetBundle加载API
AssetBundle加载API 在Unity 5当中,可以通过4个不同的API来加载AssetBundle,4个API可以用两个条件来区分: AssetBundle是 LZMA压缩. LZ4压缩还是 ...
- elementUI el-select 多选情况下包含全部选项,及获得选中项的label
<template> <div> <span style="margin-left:30px;font-weight:bolder;">教练: ...
- 分布式消息队列RocketMQ与Kafka架构上的巨大差异
分布式消息服务 Kafka 是一个高吞吐.高可用的消息中间件服务,适用于构建实时数据管道.流式数据处理.第三方解耦.流量削峰去谷等场景,具有大规模.高可靠.高并发访问.可扩展且完全托管的特点,是分布式 ...
- 03_set slice的时间复杂度
set slice O(n+k) 使用切片赋值来解释set slice的时间复杂度 (1) 对li[0:3]赋值首先会删除1,2,3,空出来的位置被后面的元素依次向前移动填充,由del slice 得 ...
- 随手记录-linux-添加epel源
下载各种yum源 https://opsx.alibaba.com/mirror https://blog.csdn.net/harbor1981/article/details/51135623
- bash登录过程 其实还不太了解,先码后看
在刚登录Linux时,首先启动 /etc/profile 文件,然后再启动用户目录下的 ~/.bash_profile. ~/.bash_login或 ~/.profile文件中的其中一个,执行的顺序 ...
- sprint3(第一天)
1.今天计划了sprint3要做的内容: 整合前台和后台,然后发布让用户使用,然后给我们反馈再进行改进 2.backlog表格: ID Name Est How to demo 1 实现用户登录与权限 ...
- 20135313-exp2
北京电子科技学院(BESTI) 实 验 报 告 课程:Java程序设计 班级:1353 姓名:吴子怡(20135313) 成绩: 指导教师:娄嘉鹏 实验日期 ...
- SpringMVC 常用注释
@Controller Controller控制器是通过服务接口定义的提供访问应用程序的一种行为 @Repository Dao层的标志 @RequestMapping 标注控制层函数的访问路径 ...
- Oracle安装后出现的问题
安装oracle没有勾选"安装模板数据库",可以通过执行以下命令进行修改: cd $ORACLE_HOME/rdbms/admin 到这个目录下sqlplus /as sysdba ...