先用线段树预处理出每个数最终的位置.然后用BIT维护最长上升子序列就行了.

用线段树O(nlogn)O(nlogn)O(nlogn)预处理就直接倒着做,每次删去对应位置的数.具体看代码

CODE

#include<bits/stdc++.h>
using namespace std;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<15,stdin),cs==ct)?0:*cs++)
template<class T>inline void read(T &res) {
char ch; int flg = 1; while(!isdigit(ch=getc()))if(ch=='-')flg=-flg;
for(res=ch-'0';isdigit(ch=getc());res=res*10+ch-'0'); res*=flg;
}
const int MAXN = 100005;
int n, m, x[MAXN], rk[MAXN], ans, sz[MAXN<<2], T[MAXN];
inline void chkmax(int &x, int y) { if(y > x) x = y; }
inline void upd(int x, int val) { for(; x <= n; x += x&-x) chkmax(T[x], val); }
inline int qsum(int x) { int re = 0; for(; x; x -= x&-x) chkmax(re, T[x]); return re; }
inline void upd(int i) { sz[i] = sz[i<<1] + sz[i<<1|1]; }
void build(int i, int l, int r) {
if(l == r) { sz[i] = 1; return; }
int mid = (l + r) >> 1;
build(i<<1, l, mid);
build(i<<1|1, mid+1, r);
upd(i);
}
int query(int i, int l, int r, int k) {
if(l == r) { sz[i] = 0; return l; }
int mid = (l + r) >> 1, re;
if(k <= sz[i<<1]) re = query(i<<1, l, mid, k);
else re = query(i<<1|1, mid+1, r, k-sz[i<<1]);
upd(i); return re;
}
int main() {
read(n); build(1, 1, n);
for(int i = 1; i <= n; ++i) read(x[i]), ++x[i];
for(int i = n; i >= 1; --i) rk[i] = query(1, 1, n, x[i]); //!
for(int i = 1, f; i <= n; ++i) {
chkmax(ans, f = qsum(rk[i]) + 1);
printf("%d\n", ans);
upd(rk[i], f);
}
}

BZOJ 3173: [Tjoi2013]最长上升子序列 (线段树+BIT)的更多相关文章

  1. BZOJ 3173: [Tjoi2013]最长上升子序列

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1524  Solved: 797[Submit][St ...

  2. Bzoj 3173: [Tjoi2013]最长上升子序列 平衡树,Treap,二分,树的序遍历

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1183  Solved: 610[Submit][St ...

  3. BZOJ 3173: [Tjoi2013]最长上升子序列( BST + LIS )

    因为是从1~n插入的, 慢插入的对之前的没有影响, 所以我们可以用平衡树维护, 弄出最后的序列然后跑LIS就OK了 O(nlogn) --------------------------------- ...

  4. BZOJ 3173: [Tjoi2013]最长上升子序列 [splay DP]

    3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1613  Solved: 839[Submit][St ...

  5. bzoj 3173 [Tjoi2013]最长上升子序列 (treap模拟+lis)

    [Tjoi2013]最长上升子序列 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2213  Solved: 1119[Submit][Status] ...

  6. bzoj 3173: [Tjoi2013]最长上升子序列【dp+线段树】

    我也不知道为什么把题看成以插入点为结尾的最长生生子序列--还WA了好几次 先把这个序列最后的样子求出来,具体就是倒着做,用线段树维护点数,最开始所有点都是1,然后线段树上二分找到当前数的位置,把这个点 ...

  7. BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告

    这个题感觉比较简单,但却比较容易想残.. 我不会用树状数组求这个原排列,于是我只好用线段树...毕竟 Gromah 果弱马. 我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这 ...

  8. 【BZOJ】3173: [Tjoi2013]最长上升子序列(树状数组)

    [题意]给定ai,将1~n从小到大插入到第ai个数字之后,求每次插入后的LIS长度. [算法]树状数组||平衡树 [题解] 这是树状数组的一个用法:O(n log n)寻找前缀和为k的最小位置.(当数 ...

  9. BZOJ 3173: [Tjoi2013]最长上升子序列 Splay

    一眼切~ 重点是按照 $1$~$n$ 的顺序插入每一个数,这样的话就简单了. #include <cstdio> #include <algorithm> #define N ...

随机推荐

  1. PTA(Advanced Level)1025.PAT Ranking

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  2. ARM 版本 瀚高 数据库的启动命令

    1. 在瀚高安装目录下面执行路径 安装目录为: /opt/HighGoDB-4.3.4.3/ bin下./pg_ctl restart -D ../data 本次的密码是: highgo123   2 ...

  3. java8 用法小结

    一 简单的stream parallelStream慎用,除非你知道它内部干了什么 List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, ...

  4. Linux系列:进阶之jdk、X window安装与使用

    1.安装x window 分为两步: 1.安装 x window,执行指令yum groupinstall “X Window” 2.安装GNOME Desktop,执行指令yum groupinst ...

  5. 【POI】使用POI 创建生成XLS,打开xls文件提示【此文件中某些文本格式可能已经更改,因为它已经超出最多允许的字体数。】

    使用POI 创建生成XLS,打开xls文件提示[此文件中某些文本格式可能已经更改,因为它已经超出最多允许的字体数.] 原因: 是因为在POI处理xls的过程中,太多次调用了: HSSFFont fon ...

  6. 8-Perl 哈希

    1.Perl 哈希哈希是 key/value 对的集合.Perl中哈希变量以百分号 (%) 标记开始.访问哈希元素格式:${key}.以下是一个简单的哈希实例:#!/usr/bin/perl%data ...

  7. EntityFramework学习要点记一

    一.Entity的注解属性(Annotations)不管是code first还是db first,都需要用到注解属性,至于用System.ComponentModel.DataAnnotations ...

  8. [Scala] java使用scala的jar包问题:Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Short

    场景 刚写的scala处理bmp文件的实验, 打了jar包让java调用一下, 结果发生这个错误. package org.tanglizi.bmp.demo; import org.tanglizi ...

  9. Linux--环境变量配置文件

    Linux系统中环境变量配置文件分为两类: 全局环境变量配置文件 /etc/profile 用户环境变量配置文件 ~/.bash_profile . ~/.bash_login ~/.profile ...

  10. Nginx作为静态资源web服务之文件读取

    Nginx作为静态资源web服务之文件读取 文件读取会使用到以下几个配置 1. sendfile 使用nginx作为静态资源服务时,通过配置sendfile可以有效提高文件读取效率,设置为on表示启动 ...