bzoj1046

来源:互联网 发布:淘宝九一一正品折扣店 编辑:程序博客网 时间:2024/06/05 19:58

这里写图片描述我语文太差,把题意读错了,写TLE好几次

就不粘题面了。。。

题目中的字典序是按标号排的,我还以为是数字的字典序。。。。。。。

这样就先倒着做一下最长上升子序列,呜呜,我懒用的lower_bound 。(注:得先变成负的)
然后对于每个询问贪心O(n)扫一遍序列就好,您懂得

放上丑代码(看不成。。对拍用吧,,,也许您一遍就A了)

#include<bits/stdc++.h>using namespace std;#define FOR(i,s,t) for(int i=(s);i<=(t);i++)inline int read(void) {    int x = 0, c, f = 1;    do {c=getchar(); if(c=='-') f = -1;} while(c<'0'||c>'9');    do {x = x*10+c-'0';c=getchar();}while(c>='0'&&c<='9');    return x * f;}const int N = 11000, INF = 0x3f3f3f3f;int n, q[N], f[N], a[N];inline void solve(int x){    int last = -INF;    for (int i = 1; i <= n && x; i++) {        if (f[i] >= x && a[i] > last) {            x--;            printf("%d",a[i]);            if (x) putchar(' ');            last = a[i];        }    }    putchar('\n');}int main() {    n = read();    memset(q,0x7f,sizeof q);    for (int i = 1; i <= n; i++) {        a[i] = read();    }    for (int i = n; i; i--) {        int pos = lower_bound(q + 1, q + n + 1, -a[i]) - q;        f[i] = pos;        q[pos] = -a[i];    }    int mx = lower_bound(q + 1, q + n + 1, INF) - q - 1;    int m = read(), x;    while (m--) {        x = read();        if (x > mx) puts("Impossible");        else solve(x);    }}
1 0
原创粉丝点击