题意:

m次询问,问下标最小字典序的长度为x的LIS是什么

n<=10000, m<=1000

思路:

先nlogn求出f[i]为以a[i]开头的LIS长度

然后贪心即可,复杂度nm

我们正常求LIS处理出的low[i]为长度为i的LIS结尾最小元素,f[i]为以a[i]结尾的LIS长度

为了迎合题目要求,我们从数组结尾开始求最长下降子序列,得到的f[i]为以结尾开头的,以a[i]结尾的最长下降子序列,等效于以a[i]开头的LIS

其中为了不手写二分调半天。。使用了lower_bound,此时因为是找最长下降子序列,所以变成负的即可

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int n, m;
int a[maxn], low[maxn];
int f[maxn];
int main(){
scanf("%d", &n);
for(int i = ; i <= n; i++){
scanf("%d", &a[i]);
}
int cnt = ;
for(int i = n; i >= ; i--){
int t = lower_bound(low+, low++cnt, -a[i]) - low;
f[i] = t;
cnt = max(cnt, t);
low[t] = -a[i];
}
scanf("%d", &m);
for(int i = ; i <= m; i++){
int x;
scanf("%d", &x);
if(x > cnt)printf("Impossible\n");
else{
int tmp = -;
for(int j = ; j <= n; j++){
if(x && f[j] >= x && a[j] > tmp){
x--;
tmp = a[j];
printf("%d ",a[j]);
}
}printf("\n");
}
}
return ;
} /*
6
3 4 1 2 3 6
3
6
4
5
*/

BZOJ 1046 [HAOI2007]上升序列(LIS + 贪心)的更多相关文章

  1. BZOJ 1046: [HAOI2007]上升序列(LIS)

    题目挺坑的..但是不难.先反向做一次最长下降子序列.然后得到了d(i),以i为起点的最长上升子序列,接下来贪心,得到字典序最小. ----------------------------------- ...

  2. BZOJ 1046: [HAOI2007]上升序列 LIS -dp

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3438  Solved: 1171[Submit][Stat ...

  3. BZOJ 1046: [HAOI2007]上升序列【贪心+二分状态+dp+递归】

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4987  Solved: 1732[Submit][Stat ...

  4. Bzoj 1046: [HAOI2007]上升序列 二分,递推

    1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3671  Solved: 1255[Submit][Stat ...

  5. bzoj 1046 : [HAOI2007]上升序列 dp

    题目链接 1046: [HAOI2007]上升序列 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3620  Solved: 1236[Submit] ...

  6. [BZOJ 1046] [HAOI2007] 上升序列 【DP】

    题目链接:BZOJ - 1046 题目分析 先倒着做最长下降子序列,求出 f[i],即以 i 为起点向后的最长上升子序列长度. 注意题目要求的是 xi 的字典序最小,不是数值! 如果输入的 l 大于最 ...

  7. bzoj 1046: [HAOI2007]上升序列

    Description 对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ...

  8. bzoj 1046: [HAOI2007]上升序列【dp+二分】

    先从后到前做一个最长下降子序列的dp,记录f[i],我这里用的是二分(其实树状数组比较显然) 然后对于询问,超出最长上升子序列的直接输出:否则从前到后扫,f[i]>=x&&a[i ...

  9. 【BZOJ】1046 : [HAOI2007]上升序列

    1046: [HAOI2007]上升序列 题意:给定S={a1,a2,a3,…,an}问是否存在P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且 ...

随机推荐

  1. Ant Design Pro项目打开页设为登录或者其他页面

    Ant Design Pro项目打开页设为登录或者其他页面 一.打开页设为登录页 首先找到utils包中的authority文件,在该文件中找到如下代码: export function getAut ...

  2. Win7计划任务命令

    计划任务命令 schtasks C:\Users\Administrator>schtasks /? SCHTASKS /parameter [arguments] 描述: 允许管理员创建.删除 ...

  3. 小白学 Python 爬虫(40):爬虫框架 Scrapy 入门基础(七)对接 Selenium 实战

    人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...

  4. Your Ride Is Here 你的飞碟在这儿 USACO 模拟

    1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...

  5. OpenGL ES for Android

    经过半年的准备OpenGL ES for Android系列文章终于要和大家见面了,在这里定一个小目标-先吸引1000个粉丝,万一实现了呢.写关于OpenGL ES的文章开始是有一些犹豫的,因为Ope ...

  6. poj 2253 最短路 or 最小生成树

    Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sit ...

  7. 150行代码打造.net core生产力工具,你值得拥有

    你是否在初学 .net core时,被依赖注入所折磨? 你是否在开发过程中,为了注入依赖而不停的在Startup中增加注入代码,而感到麻烦? 你是否考虑过或寻找过能轻松实现自动注入的组件? 如果有,那 ...

  8. 关于爬虫的日常复习(11)—— 实战:flask+redis维护代理池(to be continue)

  9. git 查看修改账号密码

    git config user.name         查看用户名 git config user.email         查看用户邮箱 修改用户名和邮箱的命令 git config --glo ...

  10. python 栈

    栈的特点:先进后出 class Stack: def __init__(self): self.data = [] def push(self, val): self.data.append(val) ...