QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78381#5466. Permutation CompressionpaspasuyWA 2ms3384kbC++203.9kb2023-02-18 13:13:162023-02-18 13:13:20

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-18 13:13:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3384kb
  • [2023-02-18 13:13:16]
  • 提交

answer

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

using ll = long long;
#define int ll
#define all(v) (v).begin(), (v).end()

using pii = pair<int, int>;
using ar3 = array<int, 3>;
using vi = vector<int>;
using vpii = vector<pii>;
using va3 = vector<ar3>;

const int Inf = 1e9+7;

struct st {
 va3 t; // max, idx, infty_cnt
 int n;
 st(int n) : n(n) {
  t.assign(4 * n, {0, 0, 0});
 }

 void upd(int v, int vl, int vr) {
  if (t[vl][0] > t[vr][0]) {
   t[v][0] = t[vl][0];
   t[v][1] = t[vl][1];
  } else {
   t[v][0] = t[vr][0];
   t[v][1] = t[vr][1];
  }
  t[v][2] = t[vl][2] + t[vr][2];
 }

 int znach, ps;

 void set(int pos, int val) {
  ps = pos; znach = val;
  set_t(1, 0, n);
 }

 void set_t(int v, int l, int r) {
  if (r - l == 1) {
   t[v][0] = znach;
   t[v][1] = l;
   t[v][2] = (znach == -Inf);
   return;
  }
  int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
  if (ps < m) {
   set_t(vl, l, m);
  } else {
   set_t(vr, m, r);
  }
  upd(v, vl, vr);
 }

 int s, e;

 void get_max(int l, int r) {
  s = l;
  e = r;
  collect_segs(1, 0, n);
 }


 va3 f;
 int infty_count;

 void collect_segs(int v, int l, int r) {
  if (s <= l && r <= e) {
   //vl = max(vl, t[v][0]);
   // f.emplace_back(v, l, r);
   f.push_back({v, l, r});
   return;
  }
  if (r <= s || l >= e) {
   return;
  }
  int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
  collect_segs(vl, l, m);
  collect_segs(vr, m, r);
 }

 int descent_right(int v, int x, int l, int r) {
  if (r - l == 1) {
   return l;
  }
  int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
  if (t[vl][0] < x) {
   infty_count += t[vl][2];
   return descent_right(vr, x, m, r);
  } else {
   return descent_right(vl, x, l, m);
  }
 }

 int descent_left(int v, int x, int l, int r) {
  if (r - l == 1) {
   return l;
  }
  int m = (l + r) >> 1, vl = v << 1, vr = vl ^ 1;
  if (t[vr][0] < x) {
   infty_count += t[vr][2];
   return descent_left(vl, x, l, m);
  } else {
   return descent_left(vr, x, m, r);
  }
 }

 int get_right(int pos, int x) {
  infty_count = 0;
  f.clear();
  get_max(pos + 1, n);

  for (ar3 q2 : f) {
   if (t[q2[0]][0] > x) {
    int idx = descent_right(q2[0], x, q2[1], q2[2]);
    return idx - infty_count;
   }
   infty_count += t[q2[0]][2];
  }
  return n - infty_count;
 }

 int get_left(int pos, int x) {
  infty_count = 0;
  f.clear();
  get_max(0, pos);
  reverse(all(f));

  for (ar3 q2 : f) {
   if (t[q2[0]][0] > x) {
    int idx = descent_left(q2[0], x, q2[1], q2[2]);
    return idx + infty_count;
   }
   infty_count += t[q2[0]][2];
  }
  return -1 + infty_count;
 }
};

int n, m, k;

void no() {
 cout << "NO\n";
}

void yes() {
 cout << "YES\n";
}

void solve() {
 multiset<int> tools;
 cin >> n >> m >> k;
 vi a(n), b(m);
 vi idxa(n);
 vector<char> good(n, 0);
 for (int i = 0; i < n; ++i) {
  cin >> a[i]; --a[i];
  idxa[a[i]] = i;
 }
 for (int i = 0; i < m; ++i) {
  cin >> b[i]; --b[i];
  good[b[i]] = 1;
 }
 for (int i = 0; i < m - 1; ++i) {
  if (idxa[b[i]] > idxa[b[i + 1]]) {
   no();
   return;
  }
 }
 for (int i = 0; i < k; ++i) {
  int x; cin >> x;
  tools.insert(-x);
 }
 st t(n);
 for (int i = 0; i < n; ++i) {
  t.set(i, a[i]);
 }
 int to_del = n - 1;
 for (int i = 0; i < n - m; ++i) {
  while (good[to_del]) {
   --to_del;
   while (to_del < 0) {}
  }
  int cur = idxa[to_del];
  //cout << t.get_right(cur, to_del) << " ";
  //cout << t.get_left(cur, to_del) << " ";
  int len = t.get_right(cur, to_del) - t.get_left(cur, to_del) - 1;
  // cerr << len << endl;
  std::multiset<int>::iterator best = tools.lower_bound(-len);
  if (best == tools.end()) {
   no();
   return;
  }
  tools.erase(best);
  t.set(cur, -Inf);
  --to_del;
 }
 yes();
}

signed main() {
 ios_base::sync_with_stdio(0);
 cin.tie(NULL);
 int tt = 1;
 cin >> tt;
 while (tt--) {
  solve();
 }
}

详细

Test #1:

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

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: 2ms
memory: 3352kb

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

result:

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