QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#253156 | #7627. Phony | ucup-team2307 | WA | 5ms | 3700kb | C++20 | 4.3kb | 2023-11-16 19:14:39 | 2023-11-16 19:14:40 |
Judging History
answer
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
struct Fenwick {
vector<int> f;
Fenwick(int N) : f(N + 1) {}
void update(int p, int d) {
++p;
for(; p < f.size(); p += p & -p)
f[p] += d;
}
int search(int x) {
int pos = 0, cur = 0;
for(int z = 1<<20; z>>=1;)
if((pos + z) < f.size() && cur + f[pos + z] <= x) {
pos += z;
cur += f[pos];
}
return pos;
}
friend int double_search(const Fenwick &a, const Fenwick &b, int x) {
int pos = 0, cur = 0;
for(int z = 1<<20; z>>=1;)
if((pos + z) < a.f.size() &&
cur + a.f[pos + z] + b.f[pos + z] <= x) {
pos += z;
cur += a.f[pos];
cur += b.f[pos];
}
return pos;
}
};
int main() {
cin.tie(0)->sync_with_stdio(0);
ll n, m, k;
cin >> n >> m >> k;
vector<array<ll, 2>> comp;
vector<ll> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
comp.push_back({(a[i] % k + k) % k, i});
}
sort(all(comp));
map<ll, vector<int>, greater<>> blocks;
for(int i = 0; i < n; i++) {
int t = lower_bound(all(comp), array<ll, 2>{(a[i] % k + k) % k, i}) - comp.begin();
ll div = a[i] >= 0 ? a[i] / k : (a[i] - k + 1) / k;
blocks[div].push_back(t);
}
sort(all(a));//for handling prefix
ll block_id = 1ll<<62, count = 0;
Fenwick A(n), B(n);
auto upload_block = [&](int first = 0) {
auto it = blocks.begin();
for(auto i : it->second) {
A.update(i, 1);
if(!first)
B.update(i, -1);
}
count += it->second.size();
block_id = it->first;
blocks.erase(it);
if(!blocks.empty()) {
it = blocks.begin();
for(auto i : it->second)
B.update(i, 1);
}
};
upload_block(1);
ll ops = 0, t;
char c;
while(m--) {
cin >> c >> t;
if(c == 'C') {
ops += t;
while(ops >= count) {
ll cycles_do = ops / count;
ll cycles_max = 1ll<<60;
if(blocks.size())
cycles_max = block_id - blocks.begin()->first;
if(cycles_do >= cycles_max) {
ops -= cycles_max * count;
upload_block();
} else {
ops -= cycles_do * count;
block_id -= cycles_do;
}
}
} else {
t = n - t;
ll bcount = blocks.empty() ? 0 : blocks.begin()->second.size();
ll ccount = n - bcount - count;
ll b_id = blocks.empty() ? -(1ll<<60) : blocks.begin()->first;
if(m == 632)
cout << t << "_" << count << "_" << bcount << "_" << ccount << "_";
if(t < ccount) {
cout << a[t] << '\n';
} else {
int ahead_idx = count - 1 - ops;
int acount = ahead_idx + 1;
int ans;
ll base;
if(t >= n - acount) {
t -= n - acount;
ans = A.search(t);
base = block_id * k;
} else if(b_id == block_id - 1) {
base = blocks.begin()->first * k;
ans = B.search(t - ccount);
int head = A.search(ahead_idx);
if(ans >= head) {
ans = double_search(A, B, t - ccount + acount);
}
} else {
// int abcount = count - acount;
if(t >= n - count) {
t -= (n - count);
base = (block_id - 1) * k;
ans = A.search(t + acount);
} else {
t -= ccount;
base = b_id;
ans = B.search(t);
}
}
cout << base + comp[ans][0] << '\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3392kb
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: 3496kb
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: 0
Accepted
time: 0ms
memory: 3384kb
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 7018 811 6752 2561 6683 6114 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:
ok 56 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 3392kb
input:
100 300 3453213 4777243 17293302 43453992 45342348 82151965 11360220 63630258 38237802 1 56066162 75020027 83365329 100659838 2141897 73421986 102600372 100824166 46869742 31931613 26168082 41399743 62249685 31666167 96044265 81576202 44039394 94271661 37319513 46613514 14176026 23991180 3310773 635...
output:
16238806 100824166 74028301 100824166 98702945 100659838 3066866 82151965 78167694 86340309 16238806 64926204 73585978 16238806 64926204 4777243 62249685 78951605 16238806 3066866 77853267 78427881 75980670 43453992 16238806 1 78122989 62404688 72949759 3310773 35761909 44960459 73552383 72045179 16...
result:
ok 159 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
10000 10000 424242 17989609 33305173 36700219 9019831 18836819 21791961 21965035 18824893 1921235 23926509 28110961 33993409 12966853 13082665 4452379 1637119 38371575 1826245 36931693 1 33924345 30310225 30503101 4578015 31263907 15733393 40333897 34523425 25601465 11528899 18236695 4978289 9301153...
output:
29899255 19256287 20728753 27691558 11569357 18782611 6940738 25519453 36411607 15396403 20282701 5151091 13921909 21284225 20657428 13921909 19561543 11116483 30447757 38758135 7394929 27457873 34310557 1419251 40938731 25617811 25928137 21610443 40849627 18524773 24971899 24506287 4463929 27691558...
result:
ok 4977 lines
Test #6:
score: -100
Wrong Answer
time: 5ms
memory: 3700kb
input:
10000 10000 8633427 538078847 573328001 833039873 394897857 557339356 788138551 409068537 418595873 489365441 734786049 510598641 38313681 218800001 757899321 509729089 719587751 396447437 1228081 824921431 557992001 176123501 195314201 316694001 77352241 390252445 488382377 688760625 683480525 7293...
output:
741597921 684643385 244445841 679897197 788928601 972172681 949082401 473000401 79937561 724673651 683480525 854680935 660858076 235090570 532125856 394971761 439375061 765033025 256613601 932699581 712850809 553280433 133989601 529728321 79937561 753982913 438698461 756463614 719635425 653599361 78...
result:
wrong answer 4650th lines differ - expected: '139059545', found: '1407_3792_96_6112_139059545'