QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625649#7627. PhonyDBsoleilWA 1ms5824kbC++233.8kb2024-10-09 20:12:522024-10-09 20:12:54

Judging History

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

  • [2024-10-09 20:12:54]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5824kb
  • [2024-10-09 20:12:52]
  • 提交

answer


#include <bits/stdc++.h>
using namespace std;
static constexpr int64_t inf = 0x3f3f3f3f3f3f3f3f;
uint64_t randu64(void) {
  static const auto FIXED = chrono::steady_clock::now().time_since_epoch().count();
  static mt19937_64 gen(FIXED); return gen();
} // randu64
namespace treap {
  static constexpr int MaxN = 5e5 + 5;
  struct node {
    int ls, rs, size;
    uint64_t fix;
    int64_t val;
    node() = default;
    node(int64_t v) : ls(0), rs(0), size(1), fix(randu64()), val(v) { }
  } tr[MaxN];
  int tn, root;
  int newnode(int64_t v) { return tr[++tn] = node(v), tn; }
  void pushup(int p) {
    tr[p].size = tr[tr[p].ls].size + tr[tr[p].rs].size + 1;
  } // treap::pushup
  int join(int l, int r) {
    if (!l || !r) return l | r;
    if (tr[l].fix < tr[r].fix) {
      tr[l].rs = join(tr[l].rs, r);
      return pushup(l), l;
    } else {
      tr[r].ls = join(l, tr[r].ls);
      return pushup(r), r;
    }
  } // treap::join
  void split_v(int p, int64_t v, int &l, int &r) {
    if (!p) return l = r = 0, void();
    if (tr[p].val <= v) l = p, split_v(tr[p].rs, v, tr[l].rs, r), pushup(l);
    else r = p, split_v(tr[p].rs, v, l, tr[r].rs), pushup(r);
  } // treap::split_v
  void insert(int64_t v) {
    int A, B; split_v(root, v, A, B);
    root = join(A, join(newnode(v), B));
  } // treap::insert
  int64_t find_k(int k) {
    int p = root;
    // fprintf(stderr, "k = %d, root.size = %d\n", k, tr[root].size);
    while (p) {
    // fprintf(stderr, ": k = %d, p.size = %d\n", k, tr[p].size);
      if (tr[tr[p].rs].size + 1 == k) return tr[p].val;
      if (tr[tr[p].rs].size + 1 < k)
        k -= tr[tr[p].rs].size + 1, p = tr[p].ls;
      else p = tr[p].rs;
    } return -inf;
  } // treap::find_k
  int rankv(int64_t v) {
    int p = root, y = 0;
    while (p) {
      if (tr[p].val <= v) p = tr[p].rs;
      else y += tr[tr[p].rs].size + 1, p = tr[p].ls;
    } return y;
  } // treap::rankv
} // namespace treap
using treap::insert, treap::find_k, treap::rankv;
static constexpr int Maxn = 5e5 + 5;
int n, qn, tn, cur;
int64_t K, b[Maxn], add;
int64_t modK(int64_t x) { return (x %= K) < 0 ? x + K : x; }
int64_t floorK(int64_t x) { return x - modK(x); }
int main(void) {
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n >> qn >> K; tn = cur = 0;
  for (int i = 1; i <= n; ++i) cin >> b[i];
  sort(b + 1, b + n + 1, greater<int64_t>());
  int tn = 0; add = floorK(b[1]);
  while (tn <= n && floorK(b[tn + 1]) == add) insert(modK(b[++tn]));
  while (qn--) {
    string op; int64_t x;
    cin >> op >> x;
    if (op.front() == 'C') {
      while (x) {
        // fprintf(stderr, "x = %d, tn = %d, cur = %d\n", x, tn, cur);
        if (tn < n && floorK(b[tn + 1]) == add - K) {
          int y = rankv(modK(b[tn + 1])) - cur;
          if (y != 0) {
            if (x <= y) cur += x, x = 0;
            else cur += y, x -= y;
          }
          if (x != 0) {
            insert(modK(b[++tn])), ++cur;
          }
        } else {
          if (cur != 0) {
            if (tn - cur < x) x -= tn - cur, cur = 0, add -= K;
            else cur += x, x = 0;
          } else {
            if (x < tn) {
              cur = x, x = 0;
            } else {
              if (tn < n) {
                int64_t p = floorK(b[tn + 1]) + K;
                if ((add - p) / K * tn <= x)
                  x -= (add - p) / K * tn, add = p;
                else add -= x / tn * K, x %= tn;
              } else {
                add -= x / tn * K, x %= tn;
              }
            }
          }
        }
      }
    } else {
      int64_t ans = inf;
      if (x <= tn - cur) ans = find_k(cur + x) + add;
      else if (x <= tn) ans = find_k(x - (tn - cur)) + add - K;
      else ans = b[x];
      cout << ans << endl;
    }
  }
  return 0;
} // main

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5824kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5664kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5704kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8171
2945
7579
7522
5291
5001
2042
4721
4721
6881
4097
7113
7218
7201
7035
811
6752
2561
6656
6135
6115
3581
5291
1485
5904
5387
2042
5216
5186
5229
4721
5052
4029
4097
4506
4676
4484
4697
2042
4615
4468
4504
4449
3581
4345
115
2042
4358
2042
4396
1485
4251
-17584

result:

wrong answer 4th lines differ - expected: '8200', found: '8171'