QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768018#5466. Permutation CompressionwxhtzdyWA 0ms3592kbC++202.7kb2024-11-20 23:37:262024-11-20 23:37:27

Judging History

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

  • [2024-11-20 23:37:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-11-20 23:37:26]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      --a[i];
    }
    vector<int> b(m);
    for (int i = 0; i < m; i++) {
      cin >> b[i];
      --b[i];
    }
    vector<bool> del(n);
    for (int i = 0; i < m; i++) {
      del[b[i]] = true;
    }
    multiset<int> st;
    for (int i = 0; i < k; i++) {
      int l;
      cin >> l;
      st.insert(l);
    }
    vector<int> L(n);
    vector<int> R(n);
    {
      vector<int> stk;
      for (int i = 0; i < n; i++) {
        int low = 0, high = int(stk.size()) - 1, id = -1;
        while (low <= high) {
          int mid = low + high >> 1;
          if (a[stk[mid]] > a[i]) {
            id = stk[mid];
            low = mid + 1;
          } else {
            high = mid - 1;
          }
        }
        L[i] = id;
        if (del[a[i]]) {
          while (!stk.empty() && a[stk.back()] < a[i]) {
            stk.pop_back();
          }
          stk.push_back(i);
        }
      }
    }
    {
      vector<int> stk;
      for (int i = n - 1; i >= 0; i--) {
        int low = 0, high = int(stk.size()) - 1, id = n;
        while (low <= high) {
          int mid = low + high >> 1;
          if (a[stk[mid]] > a[i]) {
            id = stk[mid];
            low = mid + 1;
          } else {
            high = mid - 1;
          }
        }
        R[i] = id;
        if (del[a[i]]) {
          while (!stk.empty() && a[stk.back()] < a[i]) {
            stk.pop_back();
          }
          stk.push_back(i);
        }
      }
    }
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) {
      return a[i] > a[j];
    });
    vector<int> fenw(n);
    auto Modify = [&](int p, int v) {
      while (p < n) {
        fenw[p] += v;
        p |= (p + 1);
      }
    };
    auto Query = [&](int p) {
      int v = 0;
      while (p >= 0) {
        v += fenw[p];
        p = (p & (p + 1)) - 1;
      }
      return v;
    };
    for (int i = 0; i < n; i++) {
      Modify(i, +1);
    }
    bool ok = true;
    for (int i : order) {
      if (del[a[i]]) {
        continue;
      }
      int need = Query(R[i] - 1) - Query(L[i]);
      Modify(i, -1);
      auto it = st.lower_bound(need + 1);
      if (it == st.begin()) {
        ok = false;
        break;
      }
      it = prev(it);
      st.erase(it);
    }
    cout << (ok ? "YES" : "NO") << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

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