这个题感觉比较简单,但却比较容易想残。。

我不会用树状数组求这个原排列,于是我只好用线段树。。。毕竟 Gromah 果弱马。

我们可以直接依次求出原排列的元素,每次找到最小并且最靠右的那个元素,假设这是第 $i$ 次找的,那么这就是原排列的第 $i$ 项,然后我们就把这个元素删去(变成很大的数),再把这个数以左的数都加 1,进行下一轮。

然后就是裸的最长上升子序列啦~~~

时间复杂度 $O(n\log n)$,空间复杂度 $O(n)$。

 #include <cstdio>
#include <algorithm>
using namespace std;
#define N 100000 + 5
#define M 262144 + 5
#define ls(x) x << 1
#define rs(x) x << 1 | 1 int n, Pos[N], A[N], T[N], F[N]; struct Segment_Tree
{
int Min, delta;
}h[M]; inline void Build(int x, int l, int r)
{
if (l == r)
{
h[x].Min = Pos[l];
return ;
}
int mid = l + r >> ;
Build(ls(x), l, mid);
Build(rs(x), mid + , r);
h[x].Min = min(h[ls(x)].Min, h[rs(x)].Min);
} inline void apply(int x, int d)
{
h[x].Min += d, h[x].delta += d;
} inline void push(int x)
{
if (h[x].delta)
{
apply(ls(x), h[x].delta);
apply(rs(x), h[x].delta);
h[x].delta = ;
}
} inline void Modify(int x, int l, int r, int s, int t, int d)
{
if (l == s && r == t)
{
apply(x, d);
return ;
}
push(x);
int mid = l + r >> ;
if (t <= mid) Modify(ls(x), l, mid, s, t, d);
else if (s > mid) Modify(rs(x), mid + , r, s, t, d);
else Modify(ls(x), l, mid, s, mid, d), Modify(rs(x), mid + , r, mid + , t, d);
h[x].Min = min(h[ls(x)].Min, h[rs(x)].Min);
} inline int Query(int x, int l, int r)
{
if (l == r) return l;
int mid = l + r >> ;
if (h[rs(x)].Min <= h[ls(x)].Min)
return Query(rs(x), mid + , r);
else return Query(ls(x), l, mid);
} int main()
{
#ifndef ONLINE_JUDGE
freopen("3173.in", "r", stdin);
freopen("3173.out", "w", stdout);
#endif scanf("%d", &n);
for (int i = ; i <= n; i ++)
scanf("%d", Pos + i);
Build(, , n);
for (int i = ; i <= n; i ++)
{
int t = Query(, , n);
Modify(, , n, , t, );
Modify(, , n, t, t, n);
if (!T[] || T[T[]] < t)
{
T[++ T[]] = t;
F[t] = T[];
}
else
{
int x = lower_bound(T + , T + T[] + , t) - T;
T[x] = t;
F[t] = x;
}
}
for (int i = , Max = ; i <= n; i ++)
{
Max = Max > F[i] ? Max : F[i];
printf("%d\n", Max);
} #ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return ;
}

3173_Gromah

BZOJ 3173 [Tjoi2013] 最长上升子序列 解题报告的更多相关文章

  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]最长上升子序列 (线段树+BIT)

    先用线段树预处理出每个数最终的位置.然后用BIT维护最长上升子序列就行了. 用线段树O(nlogn)O(nlogn)O(nlogn)预处理就直接倒着做,每次删去对应位置的数.具体看代码 CODE #i ...

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

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

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

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

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

    原题:http://www.lydsy.com/JudgeOnline/problem.php?id=3173 题解:促使我写这题的动力是,为什么百度遍地是Treap,黑人问号??? 这题可以用线段树 ...

随机推荐

  1. MyBatis(3.2.3) - Configuring MyBatis using XML, typeAliases

    In the SQL Mapper configuration file, we need to give the fully qualified name of the JavaBeans for ...

  2. 【AngularJs】---$sce 输出Html

    [问题描述] angular js的强大之处之一就是他的数据双向绑定功能----->ng-bind和针对form的ng-model 但在我们的项目当中会遇到这样的情况,后台返回的数据中带有各种各 ...

  3. MVC中使用AuthorizeAttribute注意事项

    代码调用顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest 如果AuthorizeCore返回false时,才会 ...

  4. Android 全屏相关操作

    1.隐藏标题栏(titlebar) (1)在代码中隐藏标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); (2)在Manifest中Applicati ...

  5. Android之触屏事件

    方法一: 新建"MyView"类 package onTouchEvent; import android.content.Context; import android.grap ...

  6. RDD机制实现模型Spark初识

    Spark简介 Spark是基于内存计算的大数据分布式计算框架.Spark基于内存计算,提高了在大数据环境下数据处理的实时性,同时保证了高容错性和高可伸缩性.       在Spark中,通过RDD( ...

  7. VS2010与QT的集成开发环境

    http://blog.csdn.net/hbsong75/article/details/9293773 QT与Java有点类似,也是一种跨平台的软件(当然在windows平台和Linux平台需要安 ...

  8. 判断DataReader中是否有指定列

    取出的DataReader如果在读取过程中报没有列的错误可以用这个方法. //调用该方法判断datareader中是否有指定列 public static bool readerExists(IDat ...

  9. C#中Excel的导入和导出的几种基本方式

    在上一篇(http://www.cnblogs.com/fengchengjushi/p/3369386.html)介绍过,Excel也是数据持久化的一种实现方式.在C#中.我们常常会与Excel文件 ...

  10. [译]使用Babel和Browserify创建你的ES6项目

    原文地址:Setting up an ES6 Project Using Babel and Browserify JavaScript的发展日新月异,ES6很快就要接管JS了.很多著名的框架像Ang ...