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 ...
随机推荐
- linux for 循环的小应用
[root@localhost ~]# mkdir -pv /home/data{1..5} # 创建多个目录 以下两种方法类似. for i in {1..5};do echo "&l ...
- lua编程之元表与元方法
一. 前言 lua是一种非常轻量的动态类型语言,在1993年由由Roberto Ierusalimschy.Waldemar Celes 和 Luiz Henrique de Figueiredo等人 ...
- Jmeter+ant+jenkins接口自动化测试 平台搭建(一)
平台简介 一个完整的接口自动化测试平台需要支持接口的自动执行,自动生成测试报告,以及持续集成.Jmeter 支持接口的测试,Ant 支持自动构建,而 Jenkins 支持持续集成,所以三者组合在一起可 ...
- oracle 数据库的详细安装教程
由于oracle数据库比较大 所以安装的时候比较慢是目前装的最大的软件了吧 而且如果装崩了 可能还会重装系统 不过比较幸运 一次就装好 1.需要去官网下载 https://www.oracle.co ...
- NO--14 微信小程序,左右联动二
上一篇讲解了左=>右联动,那个还比较简单,本篇写剩下比较核心的部分,也是本次开发过程中遇到最难的部分,右=>左联动,先简单看一下演示 右左联动.gif 一.关键技术: (1) 小程序 ...
- python的eval和json.loads(),json.dumps()
eval() 将字符串当成一个表达式去执行,可以想象成一个去字符串然后执行的操作. In [1]: s = '3*8' In [2]: eval(s) Out[2]: 24 eval()和json.l ...
- 推荐3个小程序开源组件库——Vant、iView、ColorUI
推荐3个小程序开源组件库 在进行小程序开发时,经常会遇到编写组件方面的阻碍,这让我们花费大量的时间在页面以及 CSS 样式编写上.因此可以使用开源组件库,有些复杂的组件可以直接拿来使用,节省开发时间, ...
- GNU Radio GRC HackRF实现FM接收
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- Tree - AdaBoost with sklearn source code
In the previous post we addressed some issue of decision tree, including instability, lack of smooth ...
- python 根据年月日,计算是这一年中的第几天
利用python计算某一天是这一年中的第几天,例如,给定年份= 2019年,月份= 1,日期= 3,则返回3:因为2019-01-03日期是2019年的第3 天. 首先,我们要知道闰年.平年怎么区分: ...