QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#259150#5466. Permutation Compressionkai_weiWA 1ms3572kbC++202.7kb2023-11-20 17:19:422023-11-20 17:19:43

Judging History

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

  • [2023-11-20 17:19:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3572kb
  • [2023-11-20 17:19:42]
  • 提交

answer

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

const int N = 2e5 + 5;
int tr[N];  // n数的个数
int n, m, k;
int lowbit(int x) {
    return x & (-x);
}
void add(int i, int a) {  // 单点增加
    while (i <= n) {
        tr[i] += a;
        i += lowbit(i);
    }
}
int ask(int i) {  // 前缀和查询
    int ans = 0;
    while (i != 0) {
        ans += tr[i];
        i -= lowbit(i);
    }
    return ans;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        cin >> n >> m >> k;
        vector<int> pos(n + 1), query(n + 1), b(n + 1);
        multiset<int> tool;
        set<int> inter;
        for (int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            pos[x] = i;
            tr[i] = 0;
        }
        int last = 0;
        int fl = 0;
        for (int i = 1; i <= m; i++) {
            int x;
            cin >> x;
            b[i] = x;
            if (pos[last] > pos[x]) {  // 判断顺序
                fl = 1;
            }
            query[x] = 1;
            last = x;
        }
        for (int i = 1; i <= k; i++) {
            int x;
            cin >> x;
            tool.insert(x);
        }
        if (fl) {
            // cout << "x" << endl;
            cout << "NO" << endl;
            continue;
        }
        inter.insert(0);
        inter.insert(n + 1);
        for (int i = n; i >= 1; i--) {
            if (query[i]) {  // 如果要留则直接放入区间
                inter.insert(pos[i]);
                continue;
            }
            auto r = inter.lower_bound(pos[i]);  // 找到右区间
            auto l = prev(r);                    // 找到左区间
            int L = *l, R = *r;
            int len = R - L - (ask(R) - ask(L)) - 1;
           // cout << len << ' ' << i << endl;
            auto it = tool.upper_bound(len);
            // cout << tool.size() << endl;
            if (it == tool.begin()) {
                fl = 1;
                break;
            }
            it = prev(it);  // 找小于等于len的最大值
            tool.erase(it);
            add(pos[i], 1);
        }
        if(t==48){
            cout<<n<<' '<<m<<' '<<k<<'|';
            for(int i=1;i<=n;i++){
                cout<<pos[i]<<' ';
            }
            cout<<"|";
            for(int i=1;i<=m;i++){
                cout<<b[i]<<' ';
            }
            cout<<"|";
            for(auto it:tool){
                cout<<it<<' ';
            }
        }

        if (fl) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }
}
// 4 2 3|1 3 2 4 |1 0 1 0 |1 2

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

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: 3572kb

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
4 2 3|1 3 2 4 |1 3 |1 2 NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YE...

result:

wrong answer 52nd lines differ - expected: 'YES', found: '4 2 3|1 3 2 4 |1 3 |1 2 NO'