QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#546316 | #7627. Phony | Palbudir | WA | 1ms | 3788kb | C++20 | 3.0kb | 2024-09-03 23:11:05 | 2024-09-03 23:11:06 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using i80 = __int128;
void work() {
int n, m, q;
i64 k;
std::cin >> n >> m >> k;
std::vector<i64> a(n), b, te;
std::set<i64> set;
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
set.insert(-(a[i] % k));
}
for (auto it : set) {
b.push_back(-it);
}
q = b.size();
std::map<i64, int> map;
for (int i = 0; i < q; ++i) {
map[b[i]] = i + 1;
// std::cout << i << ";" << b[i] << "\n";
}
te.resize(q + 1);
auto add = [&](int k, int x) {
for (int i = k; i <= q; i += i & -i) {
te[i] += x;
}
};
auto ask = [&](int k) {
int sum = 0;
for (int i = k; i; i -= i & -i) {
sum += te[i];
}
return sum;
};
std::sort(a.begin(), a.end(), std::greater<>());
int rn = 1, p = 0, np;
i64 d = a[0] / k, nd;
add(map[a[0] % k], 1);
while (rn < n && a[rn] / k >= d) {
add(map[a[rn] % k], 1);
++rn;
}
while (m--) {
std::string str;
i64 x;
std::cin >> str >> x;
if (str[0] == 'C') {
nd = d - x / rn;
np = p + x % rn;
if (np >= rn) {
--nd;
np %= rn;
}
// std::cout << nd << ";" << np << "|" << rn << "\n";
while (rn < n && a[rn] / k >= nd - 1) {
add(map[a[rn] % k], 1);
x += d - 1 - a[rn] / k;
++rn;
++p;
nd = d - x / rn;
np = p + x % rn;
if (np >= rn) {
--nd;
np %= rn;
}
}
p = np, d = nd;
} else {
--x;
if (x < rn) {
int lo = 1, hi = q, mid, res;
while (hi - lo > 1) {
mid = (lo + hi) / 2;
if ((x + p) % rn >= ask(mid - 1)) {
lo = mid;
} else {
hi = mid;
}
}
if ((x + p) % rn >= ask(hi - 1)) {
res = b[hi - 1];
} else {
res = b[lo - 1];
}
if (x + p >= rn) {
std::cout << res + k * (d - 1) << "\n";
} else {
std::cout << res + k * (d) << "\n";
}
} else {
std::cout << a[x] << "\n";
}
}
// std::cout << d << ";" << p << "|" << rn << "\n";
// for (int i = 1; i <= q; ++i) {
// std::cout << ask(i) - ask(i - 1) << ",\n"[i == q];
// }
}
return;
}
int main() {
std::ios::sync_with_stdio(0);
// std::cin.tie(0), std::cout.tie(0);
int t = 1;
while (t--) {
work();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3788kb
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: 3536kb
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: 3632kb
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'