bzoj3173
Description
Input
Output
Sample Input
0 0 2
Sample Output
1
2
HINT
100%的数据 n<=100000
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#define il inline
#define re register
using namespace std;
const int N=;
int l[N],r[N],rnd[N],siz[N],v[N],s[N],cnt,now,root,n,ans[N],g;
il void update(re int k){
siz[k]=siz[l[k]]+siz[r[k]]+;
}
il void rturn(re int &k){
int t=l[k];l[k]=r[t];r[t]=k;update(k);update(t);k=t;
}
il void lturn(re int &k){
int t=r[k];r[k]=l[t];l[t]=k;update(k);update(t);k=t;
}
il void insert(re int &k,re int rank){
if(!k){
k=(++cnt);rnd[k]=rand();siz[k]=;return;
}
siz[k]++;
if(siz[l[k]]<rank){
insert(r[k],rank-siz[l[k]]-);
if(rnd[r[k]]<rnd[k]) lturn(k);
}
else{
insert(l[k],rank);
if(rnd[l[k]]<rnd[k]) rturn(k);
}
}
il int read(){
re int hs=;re char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)){
hs=(hs<<)+(hs<<)+c-'';
c=getchar();
}
return hs;
}
il void dfs(re int k){
if(!k) return;
dfs(l[k]);
v[++now]=k;
dfs(r[k]);
}
int main(){
memset(s,,sizeof(s));s[]=-;n=read();
for(re int i=,x;i<=n;i++){
x=read();insert(root,x);
}
dfs(root);
for(re int i=,t;i<=n;i++){
t=upper_bound(s,s+g+,v[i])-s;
if(s[t-]<=v[i]){
s[t]=min(s[t],v[i]);
ans[v[i]]=t;
g=max(g,t);
}
}
for(re int i=;i<=n;i++){
ans[i]=max(ans[i-],ans[i]);
printf("%d\n",ans[i]);
}
return ;
}
bzoj3173的更多相关文章
- [BZOJ3173][Tjoi2013]最长上升子序列
[BZOJ3173][Tjoi2013]最长上升子序列 试题描述 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上 ...
- [bzoj3173]最长上升子序列_非旋转Treap
最长上升子序列 bzoj-3173 题目大意:有1-n,n个数,第i次操作是将i加入到原有序列中制定的位置,后查询当前序列中最长上升子序列长度. 注释:1<=n<=10,000,开始序列为 ...
- BZOJ3173 TJOI2013最长上升子序列(splay)
容易发现如果求出最后的序列,只要算一下LIS就好了.序列用平衡树随便搞一下,这里种一棵splay. #include<iostream> #include<cstdio> #i ...
- 【LG4309】【BZOJ3173】[TJOI2013]最长上升子序列
[LG4309][BZOJ3173][TJOI2013]最长上升子序列 题面 洛谷 BZOJ 题解 插入操作显然用平衡树就行了 然后因为后面的插入对前面的操作无影响 就直接在插入完的序列上用树状数组求 ...
- 【bzoj3173】最长上升子序列
Portal --> bzoj3173 Solution 感觉自己需要智力康复qwq 首先题目给的这个序列肯定是一个\(1-n\)的排列,并且插入的顺序是从小到大 仔细思考一下会发现如果知道了最 ...
- BZOJ3173 TJOI2013最长上升子序列(Treap+ZKW线段树)
传送门 Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input ...
- bzoj3173[Tjoi2013]最长上升子序列 平衡树+lis
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2253 Solved: 1136[Submit][S ...
- bzoj千题计划316:bzoj3173: [Tjoi2013]最长上升子序列(二分+树状数组)
https://www.lydsy.com/JudgeOnline/problem.php?id=3173 插入的数是以递增的顺序插入的 这说明如果倒过来考虑,那么从最后一个插入的开始删除,不会对以某 ...
- [BZOJ3173]最长上升子序列
Problem 给你n个数A1~An,每次将i插入第Ai位后,最后输出每次插入后这个数列的最长上升子序列 Solution 这道题非常的妙.首先如果新加入的这个数构成了最长上升子序列,由于在它插入之前 ...
- BZOJ3173:[TJOI2013]最长上升子序列(Splay)
Description 给定一个序列,初始为空.现在我们将1到N的数字插入到序列中,每次将一个数字插入到一个特定的位置.每插入一个数字,我们都想知道此时最长上升子序列长度是多少? Input 第一行一 ...
随机推荐
- 通知的多线程问题 iOS
发送通知在子线程,接受也在子线程.如果子线程操作UI,会打印一推日志,告诉我们应该主线程操作.
- web中简单wcf的创建和应用
以前做过wcf控制台作为宿主,今天回顾一下,不过公司用的web直接创建就把这种过程写下来. 第一步:创建wcf页面如图 第二步:创建wcf时候已经自动生成了接口(契约)和实现类(契约),但是我们可以修 ...
- python全栈开发-面向对象-进阶
python_day_18 1,面向对象的三大特性是什么?继承,多态,封装2,什么是面向对象的新式类?什么是经典类?凡是继承object类都是新式类.凡是不继承object类都是经典类.3,面向对象为 ...
- OKHttp使用demo(证书过滤,证书导入,代理访问,文件上传)
此demo需要引入okhttp-3.4.1.jar 和 okio-1.9.0.jar(这两个包需要jdk1.7以上的环境) 对应pom文件是: <dependency> <group ...
- PLSQL变量和类型,流程控制语句,集合
---PLSQL 调试授权 GRANT debug any procedure, debug connect session TO scott; --定义变量 declare part_number ...
- java引用Arcface,实现人脸识别(demo)
## 开发环境准备: ###开发使用到的软件和工具: * Jdk8.mysql5.7.libarcsoft_face.dll(so).libarcsoft_face_engine.dll(so).li ...
- Your funds transfer has been delayed
Hello from Amazon. Your funds transfer in the amount of 9,422.88 USD has been delayed because the cr ...
- ES6的新特性(8)——数组的扩展
数组的扩展 扩展运算符 含义 扩展运算符(spread)是三个点(...).它好比 rest 参数的逆运算,将一个数组转为用逗号分隔的参数序列. console.log(...[1, 2, 3]) / ...
- 团队计划会议(二)——WBS
一.会议及WBS 因为是第一次开发android应用,所以我们对这次开发心里也没底,最后我们商量暂时先实现主要的几个骨架功能,之后再慢慢完善. 会议期间,我们根据自己的能力大致先估算了完成这些功能需要 ...
- LNMP环境+ 前后端项目部署+redis+redis扩展
LNMP 环境 (参照https://lnmp.org/install.html) wget -c http://soft.vpser.net/lnmp/lnmp1.4.tar.gz & ...