#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 43000;
const int TOTAL_QUERIES = 999976;
int optimal_pivot(int n) {
static vector<pair<int, int>> optimal(MAXN + 1, make_pair(1e8, 1e8));
static bool computed = false;
if (computed) return optimal[n].second;
computed = true;
optimal[0] = optimal[1] = {0, 0};
for (int i = 2; i <= MAXN; i++) {
int lo = 1, hi = i / 2;
while (lo < hi) {
int m1 = (lo + hi) / 2;
int m2 = m1 + 1;
int c1 = optimal[m1].first + optimal[i - m1].first + i - 1 + m1;
int c2 = optimal[m2].first + optimal[i - m2].first + i - 1 + m2;
if (c1 < c2) {
hi = m1;
} else {
lo = m2;
}
}
optimal[i] = make_pair(optimal[lo].first + optimal[i - lo].first + lo + i - 1, lo);
}
return optimal_pivot(n);
}
bool query(int x) {
static int query_cnt = 0;
static int last = -1;
query_cnt++;
assert(query_cnt <= TOTAL_QUERIES);
int cur = Query(x);
bool res = (cur == last);
last = cur;
return res;
}
void Solve(vector<int> A, vector<int> B, bool isBInside) {
int n = A.size();
if (n == 0) return;
if (n == 1) return Answer(A[0], B[0]);
int piv = optimal_pivot(n);
vector<int> Aleft, Aright;
vector<int> Bleft, Bright;
if (isBInside) { // All of B is in the box, so we remove the second half
for (int i = 0; i < n - piv; i++) {
Bleft.emplace_back(B[i]);
}
for (int i = n - piv; i < n; i++) {
Bright.emplace_back(B[i]);
query(B[i]); //
}
} else { // None of B is in the box, so we add the first half
for (int i = 0; i < piv; i++) {
Bleft.emplace_back(B[i]);
query(B[i]); // add elemens in B such that only the first half remains
}
for (int i = piv; i < n; i++) {
Bright.emplace_back(B[i]);
}
}
for (int i = 0; i < n; i++) {
if (Aright.size() == Bright.size()) {
Aleft.emplace_back(A[i]); // all A[i] in the right half is matched
} else if (Aleft.size() == Bleft.size()) {
Aright.emplace_back(A[i]); // all A[i] in the left half is matched
} else if (query(A[i])) {
Aleft.emplace_back(A[i]); // A[i] has a match is in the first half of B
} else {
Aright.emplace_back(A[i]); // A[i] has a match in the second half of B
}
}
return Solve(Aleft, Bleft, true), Solve(Aright, Bright, false);
}
void Solve(int N) {
vector<int> A, B;
for (int i = 1; i <= 2 * N; i++) {
if (query(i)) { // the current element is already in the box
B.emplace_back(i);
} else { // the current element is a new element
A.emplace_back(i);
}
}
return Solve(A, B, true);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
768 KB |
Output is correct |
2 |
Correct |
9 ms |
896 KB |
Output is correct |
3 |
Correct |
12 ms |
1024 KB |
Output is correct |
4 |
Correct |
19 ms |
1280 KB |
Output is correct |
5 |
Correct |
28 ms |
1896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
19 |
Correct |
69 ms |
4012 KB |
Output is correct |
20 |
Correct |
67 ms |
4044 KB |
Output is correct |
21 |
Correct |
55 ms |
3924 KB |
Output is correct |
22 |
Correct |
58 ms |
3828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
19 |
Correct |
69 ms |
4012 KB |
Output is correct |
20 |
Correct |
67 ms |
4044 KB |
Output is correct |
21 |
Correct |
55 ms |
3924 KB |
Output is correct |
22 |
Correct |
58 ms |
3828 KB |
Output is correct |
23 |
Correct |
67 ms |
4004 KB |
Output is correct |
24 |
Correct |
71 ms |
4024 KB |
Output is correct |
25 |
Correct |
55 ms |
4036 KB |
Output is correct |
26 |
Correct |
55 ms |
3864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
19 |
Correct |
69 ms |
4012 KB |
Output is correct |
20 |
Correct |
67 ms |
4044 KB |
Output is correct |
21 |
Correct |
55 ms |
3924 KB |
Output is correct |
22 |
Correct |
58 ms |
3828 KB |
Output is correct |
23 |
Correct |
67 ms |
4004 KB |
Output is correct |
24 |
Correct |
71 ms |
4024 KB |
Output is correct |
25 |
Correct |
55 ms |
4036 KB |
Output is correct |
26 |
Correct |
55 ms |
3864 KB |
Output is correct |
27 |
Correct |
67 ms |
4128 KB |
Output is correct |
28 |
Correct |
73 ms |
4084 KB |
Output is correct |
29 |
Correct |
56 ms |
4160 KB |
Output is correct |
30 |
Correct |
56 ms |
3944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
19 |
Correct |
69 ms |
4012 KB |
Output is correct |
20 |
Correct |
67 ms |
4044 KB |
Output is correct |
21 |
Correct |
55 ms |
3924 KB |
Output is correct |
22 |
Correct |
58 ms |
3828 KB |
Output is correct |
23 |
Correct |
67 ms |
4004 KB |
Output is correct |
24 |
Correct |
71 ms |
4024 KB |
Output is correct |
25 |
Correct |
55 ms |
4036 KB |
Output is correct |
26 |
Correct |
55 ms |
3864 KB |
Output is correct |
27 |
Correct |
67 ms |
4128 KB |
Output is correct |
28 |
Correct |
73 ms |
4084 KB |
Output is correct |
29 |
Correct |
56 ms |
4160 KB |
Output is correct |
30 |
Correct |
56 ms |
3944 KB |
Output is correct |
31 |
Correct |
68 ms |
4252 KB |
Output is correct |
32 |
Correct |
72 ms |
4144 KB |
Output is correct |
33 |
Correct |
66 ms |
4200 KB |
Output is correct |
34 |
Correct |
59 ms |
3980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
768 KB |
Output is correct |
2 |
Correct |
8 ms |
640 KB |
Output is correct |
3 |
Correct |
7 ms |
640 KB |
Output is correct |
4 |
Correct |
7 ms |
640 KB |
Output is correct |
5 |
Correct |
9 ms |
768 KB |
Output is correct |
6 |
Correct |
9 ms |
896 KB |
Output is correct |
7 |
Correct |
12 ms |
1024 KB |
Output is correct |
8 |
Correct |
19 ms |
1280 KB |
Output is correct |
9 |
Correct |
28 ms |
1896 KB |
Output is correct |
10 |
Correct |
8 ms |
768 KB |
Output is correct |
11 |
Correct |
21 ms |
1576 KB |
Output is correct |
12 |
Correct |
29 ms |
2024 KB |
Output is correct |
13 |
Correct |
25 ms |
1964 KB |
Output is correct |
14 |
Correct |
24 ms |
1884 KB |
Output is correct |
15 |
Correct |
62 ms |
3952 KB |
Output is correct |
16 |
Correct |
69 ms |
3992 KB |
Output is correct |
17 |
Correct |
57 ms |
3948 KB |
Output is correct |
18 |
Correct |
52 ms |
3788 KB |
Output is correct |
19 |
Correct |
69 ms |
4012 KB |
Output is correct |
20 |
Correct |
67 ms |
4044 KB |
Output is correct |
21 |
Correct |
55 ms |
3924 KB |
Output is correct |
22 |
Correct |
58 ms |
3828 KB |
Output is correct |
23 |
Correct |
67 ms |
4004 KB |
Output is correct |
24 |
Correct |
71 ms |
4024 KB |
Output is correct |
25 |
Correct |
55 ms |
4036 KB |
Output is correct |
26 |
Correct |
55 ms |
3864 KB |
Output is correct |
27 |
Correct |
67 ms |
4128 KB |
Output is correct |
28 |
Correct |
73 ms |
4084 KB |
Output is correct |
29 |
Correct |
56 ms |
4160 KB |
Output is correct |
30 |
Correct |
56 ms |
3944 KB |
Output is correct |
31 |
Correct |
68 ms |
4252 KB |
Output is correct |
32 |
Correct |
72 ms |
4144 KB |
Output is correct |
33 |
Correct |
66 ms |
4200 KB |
Output is correct |
34 |
Correct |
59 ms |
3980 KB |
Output is correct |
35 |
Correct |
70 ms |
4260 KB |
Output is correct |
36 |
Correct |
71 ms |
4272 KB |
Output is correct |
37 |
Correct |
59 ms |
4164 KB |
Output is correct |
38 |
Correct |
59 ms |
4000 KB |
Output is correct |