QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278954 | #7627. Phony | zeemanz | WA | 1ms | 5736kb | C++20 | 2.9kb | 2023-12-07 23:39:10 | 2023-12-07 23:39:10 |
Judging History
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)
struct Node {
int l, r, cnt;
};
vector<Node> tr;
SegTree(int n = 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 p) {
int l = tr[u].l, r = tr[u].r;
if (l == r) {
tr[u].cnt++;
return;
}
if (p <= mid) update(ls, p);
else update(rs, p);
pushup(u);
}
i64 query(int u, int k) {
int l = tr[u].l, r = tr[u].r;
if (l == r) return rem[l];
if (k <= tr[ls].cnt) return query(ls, k);
else return query(rs, 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, cnt);
while (sz < n && a[sz + 1] / k == d - 1 && a[sz + 1] % k >= r) {
tr.update(1, rnk[a[++sz] % k]), cnt++;
}
} else {
t -= (sz - cnt), cnt = 0, d--;
while (sz < n && a[sz + 1] / k >= d - (t / sz)) {
t -= (d - a[sz + 1] / k) * sz, d = a[sz + 1] / k;
tr.update(1, rnk[a[++sz] % k]);
}
d -= (t / sz), cnt = t % sz;
if (cnt) {
i64 r = tr.query(1, cnt);
while (sz < n && a[sz + 1] / k == d - 1 && a[sz + 1] % k >= r) {
tr.update(1, rnk[a[++sz] % k]), cnt++;
}
}
}
}
void ask(i64 x) {
if (x <= sz) {
if (x <= sz - cnt) {
i64 r = tr.query(1, x + cnt);
cout << d * k + r << endl;
} else {
i64 r = tr.query(1, 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 <= n; i++) rnk[rem[i]] = i;
tr = SegTree(len), tr.build(1, 1, len);
d = a[1] / k;
while (sz < n && a[sz + 1] / k == d) tr.update(1, rnk[a[++sz] % k]);
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: 1ms
memory: 5732kb
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: 5736kb
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: 5724kb
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 6991 811 6752 2561 6683 6114 6135 3581 5291 1485 5957 5360 2042 5303 5171 5205 4721 5084 4029 4097 4591 4816 4586 4705 2042 4535 4428 4603 4428 3581 4345 115 2042 4284 2042 4274 1485 4326 -17552
result:
wrong answer 18th lines differ - expected: '7018', found: '6991'