QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673209 | #7627. Phony | TLE_Automat | WA | 0ms | 3776kb | C++20 | 4.0kb | 2024-10-24 21:08:16 | 2024-10-24 21:08:17 |
Judging History
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define SZ(x) ((int)((x).size()))
#define lb(x) ((x) & (-(x)))
#define bp(x) __builtin_popcount(x)
#define bpll(x) __builtin_popcountll(x)
#define mkp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef __gnu_pbds::tree<pli, null_type, greater<pli>, __gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update> rbt;
void solve() {
int n, m; ll k;
cin >> n >> m >> k;
vector a(n + 1, 0ll);
const ll D = 1e18;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += D;
}
sort(a.begin() + 1, a.begin() + n + 1);
map<ll, int> rid;
map<int, ll> pt;
map<int, int> pos;
int mxid = 0, secid = 0;
for (int i = 1; i <= n; i++) {
ll p = a[i] / k;
if (!rid[p]) {
rid[p] = ++mxid;
pt[mxid] = p;
pos[mxid] = i - 1;
}
}
secid = mxid - 1;
int t = 0;
vector tr(n + 1, rbt());
for (int i = 1; i <= n; i++) {
ll p = a[i] / k, q = a[i] % k;
tr[rid[p]].insert({q, ++t});
}
int mxdc = 0;
auto merge = [&](int x, int y) -> int {
if (tr[x].size() > tr[y].size()) {
swap(x, y);
}
for (auto cur : tr[x]) {
tr[y].insert(cur);
}
tr[x].clear();
return y;
};
while (m--) {
char op;
cin >> op;
if (op == 'C') {
ll t;
cin >> t;
while (true) {
int tot = tr[mxid].size();
if (mxdc + t < tot) {
mxdc += t;
break;
} else if (secid == 0) {
t -= (tot - mxdc);
pt[mxid] = pt[mxid] - 1 - (t / tot);
mxdc = t % tot;
break;
} else {
t -= (tot - mxdc);
mxdc = 0;
if ((pt[mxid] - 1 - pt[secid]) * tot > t) {
pt[mxid] = pt[mxid] - 1 - (t / tot);
mxdc = t % tot;
break;
} else {
t -= (pt[mxid] - 1 - pt[secid]) * tot;
mxid = merge(mxid, secid);
pt[mxid] = pt[secid];
secid--;
}
}
}
} else {
int x;
cin >> x;
int tot = tr[mxid].size();
if (x <= tot - mxdc) {
cout << tr[mxid].find_by_order(mxdc + x)->fi + k * pt[mxid] - D << '\n';
} else {
int sectot = tr[secid].size();
if (x <= tot + sectot) {
x -= tot - mxdc;
ll l = 0, r = 2e18, ans = -1;
while (l <= r) {
ll mid = (l + r) >> 1;
int gecnt = tr[secid].order_of_key({mid - pt[secid] * k, 0}) +
min((int)tr[mxid].order_of_key({mid + k - pt[mxid] * k, 0}), mxdc);
if (gecnt >= x) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans - D << '\n';
} else {
x -= (tot + sectot);
cout << a[pos[secid] - x + 1] - D << '\n';
}
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
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: 0ms
memory: 3612kb
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: 3540kb
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: 0ms
memory: 3776kb
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 9153 4721 8182 2945 7633 7530 5291 5001 2042 4721 4721 6881 4097 7181 7208 7035 7017 811 6752 2561 6675 6114 6135 3581 5291 1485 5949 5393 2042 5303 5171 5205 4721 5081 4029 4097 4591 4811 4586 4705 2042 4535 4454 4592 4435 3581 4343 115 2042 4274 2042 4273 1485 4321 -17553
result:
wrong answer 2nd lines differ - expected: '9161', found: '9153'