QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75488#5466. Permutation CompressionBucketsmithWA 2ms5592kbC++141.9kb2023-02-05 13:08:032023-02-05 13:08:06

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:08:06]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5592kb
  • [2023-02-05 13:08:03]
  • 提交

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;
    mt19937 rnd(time(NULL));
    scanf("%d", &T);
    for(int i = 1; i <= T; i ++) {
        puts(solve() ? "YES" : "NO");
        if(i == 18 && rnd() % 2) {
            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: 2ms
memory: 3600kb

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: 0
Accepted
time: 2ms
memory: 5592kb

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
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
YES
YES
YES
YE...

result:

ok 100 lines

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3600kb

input:

99
6 1 6
1 5 3 4 2 6
1
1 2 1 1 1 6
1 1 1
1
1
1
4 1 3
3 4 1 2
1
1 1 2
2 2 1
2 1
2 1
2
1 1 1
1
1
1
2 1 2
1 2
2
1 2
1 1 1
1
1
1
1 1 1
1
1
1
3 2 2
3 2 1
2 1
1 2
3 3 1
2 3 1
2 3 1
1
6 1 5
3 4 2 5 6 1
3
4 2 1 1 1
6 4 4
1 6 5 2 3 4
1 2 3 4
5 4 4 6
2 1 1
1 2
1
1
6 5 1
2 1 4 5 6 3
2 1 4 6 3
2
6 3 6
5 6 2 1 3...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
...

result:

wrong answer 18th lines differ - expected: 'YES', found: 'NO'