QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#247719#7627. Phonyucup-team1198#WA 0ms3824kbC++203.6kb2023-11-11 15:40:492023-11-11 15:40:50

Judging History

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

  • [2023-11-11 15:40:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-11-11 15:40:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

int cnt[(1 << 20) + 228];

void build(int v, int left, int right) {
    cnt[v] = 0;
    if (left + 1 == right)
        return;
    int mid = (left + right) / 2;
    build(2 * v + 1, left, mid);
    build(2 * v + 2, mid, right);
}

void add(int v, int left, int right, int i, int x) {
    if (left + 1 == right) {
        cnt[v] += x;
        return;
    }
    int mid = (left + right) / 2;
    if (i < mid)
        add(2 * v + 1, left, mid, i, x);
    else
        add(2 * v + 2, mid, right, i, x);
    cnt[v] = cnt[2 * v + 1] + cnt[2 * v + 2];
}

int get_kth(int v, int left, int right, int k) {
    if (left + 1 == right)
        return left;
    int mid = (left + right) / 2;
    if (cnt[2 * v + 1] >= k)
        return get_kth(2 * v + 1, left, mid, k);
    return get_kth(2 * v + 2, mid, right, k - cnt[2 * v + 1]);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    long long k;
    cin >> n >> m >> k;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i)
        cin >> A[i];
    sort(A.begin(), A.end());
    vector<long long> all_rs(n);
    for (int i = 0; i < n; ++i)
        all_rs[i] = A[i] % k;
    sort(all_rs.begin(), all_rs.end());
    all_rs.resize(unique(all_rs.begin(), all_rs.end()) - all_rs.begin());
    int N = all_rs.size();

    build(0, 0, N);

    int cur_sz = 1;
    int cur_l = 0;
    long long cur_m = A.back() / k;
    auto add_num = [&](long long x) {
        x %= k;
        add(0, 0, N, lower_bound(all_rs.begin(), all_rs.end(), x) - all_rs.begin(), 1);   
    };
    add_num(A.back());
    A.pop_back();
    auto fixup_m = [&]() {
        while (!A.empty()) {
            long long m2 = A.back() / k;
            if (m2 == cur_m) {
                // consider cur_l = 0 here
                add_num(A.back());
                A.pop_back();
                ++cur_sz;
            } else if (m2 == cur_m - 1 && cur_l > 0) {
                long long r = A.back() % k;
                if (all_rs[get_kth(0, 0, N, cur_sz - cur_l)] >= r) {
                    add_num(A.back());
                    A.pop_back();
                    ++cur_sz;
                    ++cur_l;
                } else {
                    break;
                }
            } else {
                break;
            }
        }
    };
    fixup_m();
    while (m--) {
        char c;
        long long t;
        cin >> c >> t;
        if (c == 'C') {
            if (t < cur_sz - cur_l) {
                cur_l += t;
            } else {
                t -= cur_sz - cur_l;
                cur_l = 0;
                --cur_m;
                fixup_m();
                while (t >= cur_sz) {
                    long long take = min(t / cur_sz, A.empty() ? t / cur_sz : cur_m - A.back() / k);
                    cur_m -= take;
                    t -= cur_sz * take;
                    fixup_m();
                }
                cur_l = t;
            }
            fixup_m();
        } else {
            t = n + 1 - t;
            if (t <= A.size()) {
                cout << A[t - 1] << '\n';
            } else if (t <= A.size() + cur_l) {
                cout << (cur_m - 1) * k + all_rs[get_kth(0, 0, N, t - A.size() + cur_sz - cur_l)] << '\n';
            } else {
                //cerr << ' ' << t - A.size() - cur_l << '\n';
                //cerr << ' ' << get_kth(0, 0, N, t - A.size() - cur_l) << '\n';
                cout << cur_m * k + all_rs[get_kth(0, 0, N, t - A.size() - cur_l)] << '\n';
            }
        }
    }
    return 0;
}

詳細信息

Test #1:

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

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

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

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
7647
7531
5291
5001
2042
4721
4721
6881
4097
7187
7218
7035
7018
811
6752
2561
6656
6103
6135
3581
5291
1485
5957
5393
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 22nd lines differ - expected: '6683', found: '6656'