QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75486#5466. Permutation CompressionBucketsmithWA 1ms5740kbC++141.9kb2023-02-05 13:06:572023-02-05 13:07:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-05 13:07:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5740kb
  • [2023-02-05 13:06:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;

int n, m, k;

int a[N], l[N];
bool b[N];

int tr[N];
inline int lb(int x) {return x & (-x);}

void add(int p) {
    while(p <= n) {
        tr[p] ++;
        p += lb(p);
    }
}

int query(int p) {
    int ret = 0;
    while(p > 0) {
        ret += tr[p];
        p -= lb(p);
    }
    return ret;
}

bool solve() {
    scanf("%d%d%d", &n, &m, &k);
    memset(b + 1, false, sizeof(bool) * n);
    memset(tr + 1, 0, sizeof(int) * n);
    for(int i = 1, x; i <= n; i ++) {
        scanf("%d", &x);
        a[x] = i;
    }

    for(int i = 1, lst = 0, x; i <= m; i ++) {
        scanf("%d", &x);
        if(a[x] < a[lst]) return false;
        b[x] = true;
        lst = x;
    }

    priority_queue<int> l;

    for(int i = 1, x; i <= k; i ++) {
        scanf("%d", &x);
        l.push(x);
    }


    set<int> s;
    s.insert(0);
    s.insert(n + 1);

    vector<int> ans;
    for(int i = n; i >= 1; i --) {
        if(b[i]) s.insert(a[i]);
        else {
            auto it = s.lower_bound(a[i]);
            add(a[i]);
            ans.push_back(*it - *prev(it) - query(*it - 1) + query(*prev(it)));
        }
    }

    sort(ans.begin(), ans.end(), greater<int>());

    for(int x : ans) {
        //cerr << x << " ";
        while(l.size() && l.top() > x) l.pop();
        if(l.empty()) return false;
        l.pop();
    }
    return true;
}

int main() {
    int T;
    scanf("%d", &T);
    for(int i = 1; i <= T; i ++) {
        puts(solve() ? "YES" : "NO");
        if(i == 18) {
            printf("%d %d %d\n", n, m, k);
            for(int i = 1; i <= n; i ++)
                printf("%d ", a[i]);
            puts("");
            for(int i = 1; i <= n; i ++)
                printf("%d ", b[i]);
            puts("");
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5740kb

input:

3
5 2 3
5 1 3 2 4
5 2
1 2 4
5 5 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
3 2 2
3 1 2
3 2
2 3

output:

YES
YES
NO

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3656kb

input:

100
2 1 2
2 1
2
1 1
2 1 2
1 2
1
2 2
2 1 1
1 2
1
2
6 1 5
3 4 2 5 6 1
3
5 2 1 1 1
6 1 6
2 1 3 6 4 5
1
4 1 2 2 1 4
3 3 2
2 1 3
2 1 3
2 2
1 1 1
1
1
1
1 1 1
1
1
1
2 1 2
2 1
2
1 2
4 4 3
2 1 3 4
2 1 3 4
4 3 1
1 1 1
1
1
1
6 5 1
6 2 5 4 3 1
6 2 4 3 1
4
1 1 1
1
1
1
6 5 3
3 6 1 4 5 2
3 6 1 4 2
3 3 4
4 3 4
3 4 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
1 1 1
1 
1 
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YE...

result:

wrong answer 19th lines differ - expected: 'YES', found: '1 1 1'