http://www.lydsy.com/JudgeOnline/problem.php?id=1046

一直看错题。。。。。。。。。。。。。。。。。。。。。。。

这是要求位置的字典序啊QQQAAAQQQ

。。

那么就lis后直接从前往后扫就行了。。

注意输出方案不要写错。。(wa了好多发。。。)

拓展:同时如果求答案的字典序最小,那么我们可以先对所有元素排序,然后一个个去试,即维护当前的lis长度,看当前的这个点是否能被接上(因为排序后是单调的,lis也是单调的)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mkpii make_pair<int, int>
#define pdi pair<double, int>
#define mkpdi make_pair<double, int>
#define pli pair<ll, int>
#define mkpli make_pair<ll, int>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=10005, oo=~0u>>1;
int a[N], f[N], g[N], n, mx;
bool cmp(const int &a, const int &b) { return a>b; }
void lis() {
CC(g, 128);
for3(i, n, 1) {
int t=lower_bound(g+1, g+1+(n-i+1), a[i], cmp)-g; dbg(t);
f[i]=t;
g[t]=a[i];
mx=max(mx, t);
}
} int main() {
read(n);
for1(i, 1, n) read(a[i]);
lis();
int tot=getint();
while(tot--) {
int m=getint();
if(m>mx) { puts("Impossible"); continue; }
int now=-oo;
for1(i, 1, n) if(m && f[i]>=m && a[i]>now) { printf("%d", a[i]); m==1?puts(""):printf(" "); --m; now=a[i]; } //注意特判m!=0
}
return 0;
}

  


Description

对于一个给定的S={a1,a2,a3,…,an},若有P={ax1,ax2,ax3,…,axm},满足(x1 < x2 < … < xm)且( ax1 < ax2 < … < axm)。那么就称P为S的一个上升序列。如果有多个P满足条件,那么我们想求字典序最小的那个。任务给出S序列,给出若干询问。对于第i个询问,求出长度为Li的上升序列,如有多个,求出字典序最小的那个(即首先x1最小,如果不唯一,再看x2最小……),如果不存在长度为Li的上升序列,则打印Impossible.

Input

第一行一个N,表示序列一共有N个元素第二行N个数,为a1,a2,…,an 第三行一个M,表示询问次数。下面接M行每行一个数L,表示要询问长度为L的上升序列。

Output

对于每个询问,如果对应的序列存在,则输出,否则打印Impossible.

Sample Input

6
3 4 1 2 3 6
3
6
4
5

Sample Output

Impossible
1 2 3 6
Impossible

HINT

数据范围

N<=10000

M<=1000

Source

 

最新文章

  1. SqlServer 数据库 引擎优化使用(六)
  2. .net弹出框
  3. 51nod 1109 bfs
  4. PAT (Basic Level) Practise:1029. 旧键盘
  5. ​ScrollView、ListView嵌套
  6. C++ this 指针
  7. 导出Excel工具类
  8. DataTable调整顺序
  9. 尚硅谷面试第一季-13git分支相关命令
  10. Docker 入门 第四部分: Swarms
  11. 20155325 Exp8 Web基础
  12. Django-ContentType-signals 实现牛逼玩法
  13. semi-consistent简介
  14. python strip()函数的用法
  15. 【SPSS】软件介绍
  16. linux 正则表达式
  17. 谷歌翻译python接口
  18. 0606-Zuul构建API Gateway-Zuul过滤器以及禁用Zuul过滤器
  19. geoserver源码学习与扩展——跨域访问配置
  20. mysql 5.7 的 /etc/my.cnf

热门文章

  1. js dom获取
  2. android基础-Apk打包过程(了解)
  3. 〖Linux〗使用ssh登录远程主机,并在本地打开远程图形界面
  4. 如何防止SQL注入 http://zhangzhaoaaa.iteye.com/blog/1975932
  5. Makefile之大型工程项目子目录Makefile的一种通用写法
  6. ubuntu建立软ap共享无线网络
  7. 让 sphinx 支持中文、日文和韩文
  8. static 与单例模式、auto_ptr与单例模式、const 用法小结、mutable修饰符
  9. c++,当const char*为0时,不能将其直接赋给string
  10. ubuntu下修改读写权限