QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246937 | #7627. Phony | ucup-team133# | WA | 1ms | 3792kb | C++20 | 3.8kb | 2023-11-11 12:52:01 | 2023-11-11 12:52:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < int(v.size()); i++) cout << v[i] << (i + 1 == int(v.size()) ? "" : " ");
return os;
}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << "(L" << __LINE__ << ")" << endl;
#else
#define debug(x)
#endif
#include <bits/extc++.h>
using namespace __gnu_pbds;
using pbds = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;
struct info {
long long cur;
long long nxt;
int cnt;
int pref;
pbds d;
int done;
int get_kth(int k) {
debug(k);
debug(cnt);
debug(pref);
k -= pref - cnt;
debug(k);
if (cnt - done > k) {
return *d.find_by_order(k + done);
} else {
return ~*d.find_by_order(k - (cnt - done));
}
}
void exec_qry(long long &k) {
if (done != 0) {
if (k + done >= cnt) {
k -= cnt - done;
done = 0;
cur--;
} else {
done += (int) k;
k = 0;
return;
}
}
debug(k);
debug(cur);
debug(nxt);
if (cur == nxt) {
return;
}
long long t = min(cur - nxt, k / cnt);
cur -= t;
k -= t * cnt;
if (cur == nxt) {
return;
}
assert(k < cnt);
done += (int) k;
k = 0;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, 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(), [&](auto x, auto y) {
return x % k < y % k;
});
map<long long, vector<int>> b;
for (int i = 0; i < n; i++) {
b[a[i] / k].emplace_back(i);
}
vector<info> c;
{
long long last_cur = -3e18;
for (auto [i, v]: b) {
info t = {};
t.cur = i;
t.nxt = last_cur;
t.cnt = (int) v.size();
t.pref = t.cnt;
t.done = 0;
for (auto j: v) {
t.d.insert(j);
}
c.emplace_back(t);
last_cur = t.cur;
}
}
for (int i = (int) c.size() - 2; i >= 0; i--) {
c[i].pref += c[i + 1].pref;
}
auto merge = [&]() {
debug("merge");
assert(c.size() >= 2);
auto &x = c[c.size() - 1];
auto &y = c[c.size() - 2];
if (y.cnt < x.cnt) {
swap(x.d, y.d);
}
y.cnt += x.cnt;
for (auto i: x.d) {
y.d.insert(i);
}
// y.d.join(x.d);
c.pop_back();
};
auto bisect = [&](int k) {
int low = 0, high = (int) c.size();
while (high - low > 1) {
auto mid = (high + low) >> 1;
if (c[mid].pref > k) {
low = mid;
} else {
high = mid;
}
}
return low;
};
while (m--) {
string op;
cin >> op;
if (op == "A") {
int x;
cin >> x;
x--;
int s = bisect(x);
int t = c[s].get_kth(x);
if (t < 0) {
cout << (c[s].cur - 1) * k + a[~t] % k << '\n';
} else {
cout << c[s].cur * k + a[t] % k << '\n';
}
debug(s);
debug(t);
} else {
long long t;
cin >> t;
while (t > 0) {
c.back().exec_qry(t);
if (t > 0) {
merge();
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
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: 3792kb
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: 3560kb
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 7181 7218 7018 7018 811 6752 2561 6683 6103 6135 3581 5291 1485 5957 5393 2042 5303 5171 5205 4721 5084 4029 4097 4591 4816 4586 4705 2042 4535 4454 4603 4435 3581 4345 115 2042 4284 2042 4274 1485 4326 -17552
result:
wrong answer 15th lines differ - expected: '7187', found: '7181'