QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220606#7627. PhonyHeltion#WA 0ms3624kbC++202.0kb2023-10-20 16:24:062023-10-20 16:24:08

Judging History

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

  • [2023-10-20 16:24:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2023-10-20 16:24:06]
  • 提交

answer

#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using i64 = int64_t;
using u64 = int64_t;
using f64 = double_t;
constexpr i64 mod = 998244353;
i64 div_f(i64 x, i64 k) { return x / k - (x < 0 and x % k); }
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m;
  i64 k;
  cin >> n >> m >> k;
  vector<i64> a(n);
  for (i64 &ai : a) { cin >> ai; }
  ranges::sort(a);
  tree<pair<i64, int>, null_type, less<pair<i64, int>>, rb_tree_tag,
       tree_order_statistics_node_update>
      top;
  i64 d = div_f(a.back(), k), vir = 0;
  int st = n - 1;
  auto flush = [&]() {
    while (st >= 0) {
      i64 di = div_f(a[st], k);
      if (di == d) {
        top.insert({a[st] - d * k, st});
      } else if (di == d - 1 and
                 a[st] >= top.find_by_order(top.size() - vir - 1)->first) {
        vir += 1;
        top.insert({a[st] - d * k + k, st});
      } else {
        break;
      }
      st -= 1;
    }
  };
  flush();
  for (int i = 0; i < m; i += 1) {
    char c;
    cin >> c;
    if (c == 'C') {
      i64 t;
      cin >> t;
      while (t > 0) {
        if (top.size() - vir > t) {
          vir += t;
          flush();
          break;
        }
        if (vir > 0) {
          t -= top.size() - vir;
          vir = 0;
          d -= 1;
          flush();
        } else if (st == -1) {
          d -= t / top.size();
          t %= top.size();
        } else {
          i64 x = min(d - div_f(a[st], k), t / (int)top.size());
          d -= x;
          t -= x * top.size();
          flush();
        }
      }
    } else {
      int x;
      cin >> x;
      if (x > top.size()) {
        cout << a[n - x] << "\n";
        continue;
      } else if (x <= top.size() - vir) {
        cout << top.find_by_order(top.size() - vir - x)->first + d * k << "\n";
      } else {
        cout << top.find_by_order(top.size() - x + (top.size() - vir))->first +
                    (d - 1) * k
             << "\n";
      }
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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
8200
2945
7633
7530
5291
5001
2042
4721
4721
6881
4097
7167
7201
7035
7018
811
6752
2561
6656
6114
6135
3581
5291
1485
5948
5388
2042
5303
5171
5205
4721
5080
4029
4097
4591
4811
4586
4701
2042
4535
4454
4591
4435
3581
4335
115
2042
4274
2042
4273
1485
4321
-17552

result:

wrong answer 6th lines differ - expected: '7647', found: '7633'