QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278913#7627. PhonyzeemanzWA 1ms5728kbC++202.9kb2023-12-07 22:48:402023-12-07 22:48:40

Judging History

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

  • [2023-12-07 22:48:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5728kb
  • [2023-12-07 22:48:40]
  • 提交

answer

#include <bits/stdc++.h>

#define ios std::ios::sync_with_stdio(0), std::cin.tie(0)
#define endl '\n'

using namespace std;
using i64 = int64_t;

const int N = 5e5 + 5;
i64 n, m, k, a[N], rem[N], len;
map<i64, int> rnk;
i64 d, sz, cnt;

struct SegTree {
#define ls (u << 1)
#define rs (u << 1 | 1)
#define mid ((l + r) >> 1)

    vector<int> cnt;

    SegTree(int n = 0) : cnt(n << 2, 0) {}

    void pushup(int u) { cnt[u] = cnt[ls] + cnt[rs]; }

    void update(int u, int l, int r, int p) {
        if (l == r) {
            cnt[u]++;
            return;
        }
        if (p <= mid) update(ls, l, mid, p);
        else update(rs, mid + 1, r, p);
        pushup(u);
    }

    int query(int u, int l, int r, int k) {
        if (l == r) return rem[l];
        if (k <= cnt[ls]) return query(ls, l, mid, k);
        else return query(rs, mid + 1, r, k - cnt[ls]);
    }

#undef mid
#undef rs
#undef ls
} tr;

void change(i64 t) {
    if (cnt + t < sz) {
        cnt += t;
        i64 r = tr.query(1, 1, len, sz - cnt + 1);
        for (int i = sz + 1; i <= n; i++) {
            if (a[i] / k == d - 1 && a[i] % k >= r) {
                tr.update(1, 1, len, rnk[a[i] % k]);
                cnt++, sz++;
            } else break;
        }
    } else {
        t -= (sz - cnt), cnt = 0, d--;
        for (int i = sz + 1; i <= n; i++) {
            if (a[i] / k >= d - (t / sz)) {
                tr.update(1, 1, len, rnk[a[i] % k]);
                sz++;
            } else break;
        }
        d -= (t / sz), cnt = t % sz;
        if (cnt) {
            i64 r = tr.query(1, 1, len, sz - cnt + 1);
            for (int i = sz + 1; i <= n; i++) {
                if (a[i] / k == d - 1 && a[i] % k >= r) {
                    tr.update(1, 1, len, rnk[a[i] % k]);
                    cnt++, sz++;
                } else break;
            }
        }
    }
}

void ask(i64 x) {
    if (x <= sz) {
        if (x <= sz - cnt) {
            i64 r = tr.query(1, 1, len, sz - cnt - x);
            cout << d * k + r << endl;
        } else {
            i64 r = tr.query(1, 1, len, x);
            cout << (d - 1) * k + r << endl;
        }
    } else cout << a[x] << endl;
}

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], rem[i] = a[i] % k;
    sort(a + 1, a + n + 1, greater<>());

    sort(rem + 1, rem + n + 1);
    len = unique(rem + 1, rem + n + 1) - (rem + 1);
    for (int i = 1; i <= len; i++) rnk[rem[i]] = i;
    tr = SegTree(len);

    d = a[1] / k;
    for (int i = 1; i <= n; i++) {
        if (a[i] / k != d) break;
        tr.update(1, 1, len, rnk[a[i] % k]), sz++;
    }

    char op;
    i64 x;
    while (m--) {
        cin >> op >> x;
        if (op == 'C') change(x);
        else ask(x);
    }
}

int main() {
    ios;
    int T = 1;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Wrong Answer
time: 1ms
memory: 5656kb

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
293
360
176
173

result:

wrong answer 2nd lines differ - expected: '200', found: '293'