QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#278896#7627. PhonyzeemanzWA 1ms5516kbC++203.1kb2023-12-07 22:20:232023-12-07 22:20:25

Judging History

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

  • [2023-12-07 22:20:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5516kb
  • [2023-12-07 22:20:23]
  • 提交

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;
i64 d, sz, cnt;
map<i64, int> rnk;

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

    struct Node {
        int l, r, cnt;
    };

    int idx;
    vector<Node> tr;

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

    void build(int u, int l, int r) {
        tr[u].l = l, tr[u].r = r, tr[u].cnt = 0;
        if (l == r) return;
        build(ls, l, mid), build(rs, mid + 1, r);
    }

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

    void update(int u, int l, int r, int p) {
        if (l == r) {
            tr[u].cnt++;
            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 <= tr[ls].cnt) return query(ls, l, mid, k);
        else return query(rs, mid + 1, r, k - tr[ls].cnt);
    }

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

void change(i64 t) {
    if (cnt + t < sz) {
        cnt += t;
        i64 r = tr.query(1, 1, len, cnt);
        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) break;
            tr.update(1, 1, len, rnk[a[i] % k]), sz++;
        }
        d -= t / sz, cnt = t % sz;
        if (cnt) {
            i64 r = tr.query(1, 1, len, cnt);
            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 (cnt + x <= sz) {
            i64 r = tr.query(1, 1, len, cnt + x);
            cout << d * k + r << endl;
        } else {
            i64 r = tr.query(1, 1, len, x - sz + cnt);
            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, greater<>());
    len = unique(rem + 1, rem + n + 1) - (rem + 1);
    for (int i = 1; i <= len; i++) rnk[rem[i]] = i;
    tr = SegTree(len), tr.build(1, 1, 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;
}

詳細信息

Test #1:

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

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

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
719
-1712
392

result:

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