题目链接

思路

因为这些数字是从小到大加进去的,所以以当前数字结尾的最长上升子序列可以从前面位置的任何一个数字转移过来。所以只要能知道每个数字最终位于哪个位置就行了。

没想到出了treap还有什么办法求出来这个序列。看了眼题解发现用vector的insert直接模拟就能过。(纳尼?)这个函数不是应该是O(n)的吗。又手写了一个模拟,结果T了7个点。

vector模拟



数组模拟



所以vector的复杂度是O(挺快)????

代码

/*
* @Author: wxyww
* @Date: 2018-12-02 14:49:17
* @Last Modified time: 2018-12-02 17:28:41
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<set>
#include<ctime>
#include<bitset>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 100000 + 100;
ll read() {
ll x=0,f=1;char c=getchar();
while(c<'0'||c>'9') {
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9') {
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
int n;
int tree[N << 2];
namespace XDS {
void pushup(int rt) {
tree[rt] = max(tree[rt << 1],tree[rt << 1 | 1]);
}
void update(int rt,int l,int r,int pos,int c) {
if(l == r) {
tree[rt] = c;
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) update(rt << 1,l,mid,pos,c);
else update(rt << 1 | 1,mid + 1,r,pos,c);
pushup(rt);
}
int query(int rt,int l,int r,int L,int R) {
if(L > R) return 0;
if(L <= l && R >= r) return tree[rt];
int mid = (l + r) >> 1;
int ans = 0;
if(L <= mid) ans = max(ans,query(rt << 1,l,mid,L,R));
if(R > mid) ans = max(ans,query(rt << 1 | 1,mid + 1,r,L,R));
return ans;
}
}
int a[N];
vector<int>b;
int main() {
n = read();
for (int i = 1; i <= n; i++)
b.insert(b.begin() + read(), i);
for(int i = 1;i <= n;++i) a[b[i - 1]] = i;
for(int i = 1;i <= n;++i) {
int k = XDS::query(1,1,n,1,a[i] - 1);
XDS::update(1,1,n,a[i],k + 1);
printf("%d\n",XDS::query(1,1,n,1,n));
}
return 0;
}

一言

我觉得,我这辈子最灿烂的笑容,大概都奉献给我电脑屏幕了。 ——bilibili

最新文章

  1. Dijkstra算法优先队列实现与Bellman_Ford队列实现的理解
  2. 非root用户安装软件
  3. php-fpm服务挂掉
  4. 蓝牙技术BlueTooth
  5. Android_开发工具的下载和开发环境的搭建
  6. Selenium WebDriver + Grid2 + RSpec之旅(四) ----通过RSpec编写测试用例
  7. REDIS学习(1)环境搭建
  8. 多封装,少开放。强烈建议C++标准添加class之间的注入机制
  9. linux学习之八-Linux本机性能监控
  10. Java 基础 变量介绍
  11. C语言之数值计算--级数算法
  12. django rest framework authentication
  13. 如何创建 SVN 服务器,并搭建自己的 SVN 仓库 如何将代码工程添加到VisualSVN Server里面管理
  14. 分布式调用技术 RPC VS REST
  15. 常用模块 plus
  16. debian下配置网络 安装无线网卡驱动 Broadcom BCMXX系列
  17. VIM技巧:选择文本块
  18. .net 与 java 开发微服务对比
  19. 为什么JavaScript声明变量的时候鼓励加var关键字
  20. ubuntu/centos网络配置

热门文章

  1. mac下virtualbox中centos6.5虚拟机实现全屏和调整分辨率
  2. 转:Flutter Decoration背景设定(边框、圆角、阴影、形状、渐变、背景图像等)
  3. Codeforces 1154F Shovels Shop
  4. DAY04、流程控制if、while、for
  5. JQ查找到带有某个字符,并起类名,然后替换这个某个字符
  6. vue-cli:渲染过程理解2(vue init webpack方式创建)
  7. SQL to JSON Data Modeling with Hackolade
  8. 微服务 Micro services
  9. python与java的内存机制不一样;java的方法会进入方法区直到对象消失 方法才会消失;python的方法是对象每次调用都会创建新的对象 内存地址都不i一样
  10. .net core 2.0 Unable to convert MySQL date/time to System.DateTime