#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
vector<int> perm;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_Query(int x) {
return Query(perm[x - 1] + 1);
}
void my_Answer(int x, int y) {
Answer(perm[x - 1] + 1, perm[y - 1] + 1);
}
void Solve(int N) {
vector<int> uniq, others;
int cur_l = 0, cur_r = N - 1, prv = 0;
vector<int> lo(2 * N, 0), hi(2 * N, N - 1), mid(2 * N), ans(2 * N, -1);
perm = vector<int>(2 * N);
iota(perm.begin(), perm.end(), 0);
shuffle(perm.begin(), perm.end(), rng);
for (int i = 0; i < 2 * N; i++) {
if ((int)uniq.size() < N && my_Query(i + 1) > prv) {
uniq.pb(i);
prv++;
} else {
others.pb(i);
}
}
auto shift = [&](int new_l, int new_r) {
int tmp_new_l = new_l, tmp_new_r = new_r;
assert(cur_l <= cur_r);
assert(new_l <= new_r);
if (new_l < cur_l) {
swap(cur_l, new_l);
swap(cur_r, new_r);
}
// case 1: one range compeletely covers the other
if (new_r <= cur_r) {
for (int i = cur_l; i < new_l; i++) {
prv = my_Query(uniq[i] + 1);
}
for (int i = new_r + 1; i <= cur_r; i++) {
prv = my_Query(uniq[i] + 1);
}
} else if (cur_r < new_l) {
// case 2: completely disjoint
for (int i = cur_l; i <= cur_r; i++) {
prv = my_Query(uniq[i] + 1);
}
for (int i = new_l; i <= new_r; i++) {
prv = my_Query(uniq[i] + 1);
}
} else {
// intersection
for (int i = cur_l; i < new_l; i++) {
prv = my_Query(uniq[i] + 1);
}
for (int i = cur_r + 1; i <= new_r; i++) {
prv = my_Query(uniq[i] + 1);
}
}
cur_l = tmp_new_l;
cur_r = tmp_new_r;
};
function<void(int, int, vector<int>&)> go = [&](int l, int r, vector<int> &idxs) {
if (l > r || idxs.empty()) {
return;
}
int m = (l + r) / 2;
vector<int> left_half, right_half;
shift(0, m);
for (auto i : idxs) {
int ret = my_Query(i + 1);
if (ret == prv) {
ans[i] = m;
left_half.pb(i);
} else {
right_half.pb(i);
}
prv = ret;
}
go(l, m - 1, left_half);
go(m + 1, r, right_half);
};
go(0, N - 1, others);
for (int i : others) {
my_Answer(i + 1, uniq[ans[i]] + 1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
4 ms |
976 KB |
Output is correct |
5 |
Correct |
9 ms |
1452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
29 ms |
3740 KB |
Output is correct |
20 |
Correct |
29 ms |
3624 KB |
Output is correct |
21 |
Correct |
26 ms |
3616 KB |
Output is correct |
22 |
Correct |
28 ms |
3396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
29 ms |
3740 KB |
Output is correct |
20 |
Correct |
29 ms |
3624 KB |
Output is correct |
21 |
Correct |
26 ms |
3616 KB |
Output is correct |
22 |
Correct |
28 ms |
3396 KB |
Output is correct |
23 |
Incorrect |
27 ms |
3572 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
29 ms |
3740 KB |
Output is correct |
20 |
Correct |
29 ms |
3624 KB |
Output is correct |
21 |
Correct |
26 ms |
3616 KB |
Output is correct |
22 |
Correct |
28 ms |
3396 KB |
Output is correct |
23 |
Incorrect |
27 ms |
3572 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
29 ms |
3740 KB |
Output is correct |
20 |
Correct |
29 ms |
3624 KB |
Output is correct |
21 |
Correct |
26 ms |
3616 KB |
Output is correct |
22 |
Correct |
28 ms |
3396 KB |
Output is correct |
23 |
Incorrect |
27 ms |
3572 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
976 KB |
Output is correct |
9 |
Correct |
9 ms |
1452 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
7 ms |
1104 KB |
Output is correct |
12 |
Correct |
10 ms |
1508 KB |
Output is correct |
13 |
Correct |
9 ms |
1524 KB |
Output is correct |
14 |
Correct |
9 ms |
1496 KB |
Output is correct |
15 |
Correct |
27 ms |
3496 KB |
Output is correct |
16 |
Correct |
26 ms |
3512 KB |
Output is correct |
17 |
Correct |
29 ms |
3488 KB |
Output is correct |
18 |
Correct |
26 ms |
3396 KB |
Output is correct |
19 |
Correct |
29 ms |
3740 KB |
Output is correct |
20 |
Correct |
29 ms |
3624 KB |
Output is correct |
21 |
Correct |
26 ms |
3616 KB |
Output is correct |
22 |
Correct |
28 ms |
3396 KB |
Output is correct |
23 |
Incorrect |
27 ms |
3572 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |