QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259012#5466. Permutation Compressionkai_weiWA 1ms3768kbC++203.6kb2023-11-20 15:45:272023-11-20 15:45:27

Judging History

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

  • [2023-11-20 15:45:27]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3768kb
  • [2023-11-20 15:45:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, m, k;
        cin >> n >> m >> k;
        vector<int> a(n + 1), query(n + 1), tool(k + 1), id1(n + 1), b(n + 1);
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            id1[a[i]] = i;
        }
        for (int i = 1; i <= m; i++) {
            int x;
            cin >> x;
            b[i] = x;
            query[x] = 1;
        }
        for (int i = 1; i <= k; i++) {
            cin >> tool[i];
        }
        sort(tool.begin() + 1, tool.end(), greater<int>());
        vector<int> st;
        vector<pair<int, int>> inter(n + 1);
        for (int i = 1; i <= n; i++) {
            while (!st.empty() && a[st.back()] < a[i]) {
                // cout << a[st.back()] << ' ' << a[i] << ' ' << i << endl;
                inter[a[st.back()]].second = i - 1;
                // 计算每个数区间的右端点
                st.pop_back();
            }
            st.push_back(i);
        }
        while (!st.empty()) {
            inter[a[st.back()]].second = n;
            st.pop_back();
        }
        for (int i = n; i >= 1; i--) {
            while (!st.empty() && a[st.back()] < a[i]) {
                inter[a[st.back()]].first = i + 1;
                // 计算每个数区间的左端点
                st.pop_back();
            }
            st.push_back(i);
        }
        while (!st.empty()) {
            inter[a[st.back()]].first = 1;
            st.pop_back();
        }
        // int cnt = 0;
        //  for (int i = 1; i <= n; i++) {
        //      cout << ++cnt << ' ';
        //      cout << inter[i].first << ' ' << inter[i].second << endl;
        //  }
        int pos = 1;
        int ans = 0;
        for (int i = n; i >= 1; i--) {
            if (query[i] == 0) {
                int len = inter[i].second - inter[i].first + 1;
                // cout << len << ' ' << i << endl;
                while (pos <= k && len < tool[pos]) {
                    pos++;
                }
                if (pos > k) {
                    ans = -1;
                    break;
                }
                pos++;
                if (i != 1 && query[i - 1] == 0) {
                    if (inter[i].first < inter[i - 1].first && inter[i].second >= inter[i - 1].second) {
                        inter[i - 1].first = inter[i].first;
                        inter[i - 1].second = inter[i].second - 1;
                    } else if (inter[i].first <= inter[i - 1].first && inter[i].second > inter[i - 1].second) {
                        inter[i - 1].first = inter[i].first + 1;
                        inter[i - 1].second = inter[i].second;
                    }
                }
            }
        }
        // cout << pos << endl;
        // if (t == 55) {
        //     cout << n << ' ' << m << ' ' << k << "|";
        //     for (int i = 1; i <= n; i++) {
        //         cout << a[i] << ' ';
        //     }
        //     cout << '|';
        //     for (int i = 1; i <= m; i++) {
        //         cout << b[i] << ' ';
        //     }
        //     cout << '|';
        //     for (int i = 1; i <= k; i++) {
        //         cout << tool[i] << ' ';
        //     }
        // }
        for (int i = 2; i <= m; i++) {
            if (id1[b[i]] < id1[b[i - 1]]) ans = -1;
        }
        if (ans == -1) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }
}
/// 3 3 2|3 2 1 |1 1 1 |3 3

詳細信息

Test #1:

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

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

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:

wrong answer 82nd lines differ - expected: 'YES', found: 'NO'