#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
void Solve(int N) {
vector<int> uniq, others;
for (int i = 0, prv = 0; i < 2 * N; i++) {
if (Query(i + 1) > prv) {
uniq.pb(i);
prv++;
} else {
others.pb(i);
}
}
int cur_l = 0, cur_r = N - 1, prv = N;
vector<int> lo(2 * N, 0), hi(2 * N, N - 1), mid(2 * N), ans(2 * N, -1);
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 = Query(uniq[i] + 1);
}
for (int i = new_r + 1; i <= cur_r; i++) {
prv = Query(uniq[i] + 1);
}
} else if (cur_r < new_l) {
// case 2: completely disjoint
for (int i = cur_l; i <= cur_r; i++) {
prv = Query(uniq[i] + 1);
}
for (int i = new_l; i <= new_r; i++) {
prv = Query(uniq[i] + 1);
}
} else {
// intersection
for (int i = cur_l; i < new_l; i++) {
prv = Query(uniq[i] + 1);
}
for (int i = cur_r + 1; i <= new_r; i++) {
prv = Query(uniq[i] + 1);
}
}
cur_l = tmp_new_l;
cur_r = tmp_new_r;
};
for (int rep = 0; (1 << rep) <= N; rep++) {
vector<bool> can(2 * N, 0);
for (int i : others) if (lo[i] <= hi[i]) {
mid[i] = (lo[i] + hi[i]) / 2;
// insert [lo[i], mid[i]] from uniq
}
sort(others.begin(), others.end(), [&](const auto &lhs, const auto &rhs) {
if (rep % 2 == 0) {
return mid[lhs] > mid[rhs];
} else {
return mid[lhs] < mid[rhs];
}
});
for (int i : others) if (lo[i] <= mid[i]) {
shift(0, mid[i]);
int ret_1 = Query(i + 1);
if (ret_1 == prv) {
can[i] = 1;
}
prv = ret_1;
}
for (int i : others) if (lo[i] <= mid[i]) {
if (can[i]) {
ans[i] = mid[i];
hi[i] = mid[i] - 1;
} else {
lo[i] = mid[i] + 1;
}
}
}
for (int i : others) {
Answer(i + 1, uniq[ans[i]] + 1);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
592 KB |
Output is correct |
4 |
Correct |
6 ms |
848 KB |
Output is correct |
5 |
Correct |
13 ms |
1316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
6 ms |
848 KB |
Output is correct |
9 |
Correct |
13 ms |
1316 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
8 ms |
976 KB |
Output is correct |
12 |
Correct |
13 ms |
1360 KB |
Output is correct |
13 |
Correct |
13 ms |
1348 KB |
Output is correct |
14 |
Correct |
10 ms |
1244 KB |
Output is correct |
15 |
Incorrect |
32 ms |
2768 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |