QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#108431#5466. Permutation Compression6arenWA 2ms3480kbC++171.8kb2023-05-25 00:53:022023-05-25 00:53:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-25 00:53:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3480kb
  • [2023-05-25 00:53:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <cp/debugger.hpp>
#else
#define debug(...) 42
#endif

#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

typedef int64_t int64;
typedef pair<int, int> ii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), pos(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      a[i]--;
      pos[a[i]] = i;
    }
    vector<int> b(m);
    for (int &e : b) cin >> e, e--;
    vector<int> l(k);
    for (int &e : l) cin >> e;
    bool ok = true;
    for (int i = 1; i < m; i++) {
      ok &= (pos[b[i - 1]] < pos[b[i]]);
    }
    vector<int> left(n), right(n);
    {
      stack<int> st;
      for (int i = 0; i < n; i++) {
        while (!st.empty() && a[st.top()] < a[i]) st.pop();
        left[i] = (st.empty() ? -1 : st.top());
        st.push(i);
      }
    }
    {
      stack<int> st;
      for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() && a[st.top()] < a[i]) st.pop();
        right[i] = (st.empty() ? n : st.top());
        st.push(i);
      }
    }
    vector<int> in_b(n);
    for (int e : b) in_b[e] = 1;
    
    vector<int> all_lens;
    for (int i = 0; i < n; i++) {
      if (in_b[a[i]]) continue;
      int len = right[i] - left[i] - 1;
      all_lens.push_back(len);
    }
    sort(l.begin(), l.end());
    sort(all_lens.begin(), all_lens.end());
    int cur = 0;
    if (sz(l) < sz(all_lens)) {
      ok = false;
    } else {
      for (int i = 0; i < sz(all_lens); i++) {
        ok &= (l[i] <= all_lens[i]);
      }
    }
    cout << (ok ? "YES\n" : "NO\n");
  }
  
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3480kb

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: 0ms
memory: 3384kb

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'