#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 45005;
bool In[2 * MAXN];
int lst = 0;
bool query(int i) {
In[i] ^= 1;
int cur = Query(i);
bool ans = cur != lst;
return lst = cur, ans;
}
int idx[2 * MAXN];
vector<int> A, B;
vector<pair<int, int>> pairs;
constexpr double rat = 1 / 2.56; //ternary
void dfs(int l, int r, const vector<int>& b, bool is_on) {
if(l == r) {
assert(b.size() == 1);
pairs.emplace_back(idx[A[l]], idx[b[0]]);
return;
}
int m = l + (r - l) * rat;
for(int i = l; i <= m; i++) query(idx[A[i]]);
vector<int> lf, rg;
for(int id: b) {
if(lf.size() == m - l + 1) rg.push_back(id);
else if(rg.size() == r - m) lf.push_back(id);
else (query(idx[id]) == is_on ? lf : rg).push_back(id);
}
dfs(l, m, lf, is_on ^ 1);
if(m < r) dfs(m + 1, r, rg, is_on);
}
void Solve(int n) {
mt19937 rng(233);
iota(idx + 1, idx + (2 * n) + 1, 1);
shuffle(idx + 1, idx + (2 * n) + 1, rng);
for(int i = 1; i <= 2 * n; i++) (query(idx[i]) ? A : B).push_back(i);
dfs(0, n - 1, B, 1);
assert(pairs.size() == n);
for(auto& x: pairs) Answer(x.first, x.second);
}
Compilation message
minerals.cpp: In function 'void dfs(int, int, const std::vector<int>&, bool)':
minerals.cpp:31:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
31 | if(lf.size() == m - l + 1) rg.push_back(id);
| ~~~~~~~~~~^~~~~~~~~~~~
minerals.cpp:32:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
32 | else if(rg.size() == r - m) lf.push_back(id);
| ~~~~~~~~~~^~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from minerals.cpp:2:
minerals.cpp: In function 'void Solve(int)':
minerals.cpp:45:25: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
45 | assert(pairs.size() == n);
| ~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
328 KB |
Output is correct |
2 |
Correct |
2 ms |
456 KB |
Output is correct |
3 |
Correct |
4 ms |
584 KB |
Output is correct |
4 |
Correct |
6 ms |
840 KB |
Output is correct |
5 |
Correct |
13 ms |
1352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
19 |
Correct |
39 ms |
3020 KB |
Output is correct |
20 |
Correct |
41 ms |
3028 KB |
Output is correct |
21 |
Correct |
38 ms |
3040 KB |
Output is correct |
22 |
Correct |
39 ms |
2876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
19 |
Correct |
39 ms |
3020 KB |
Output is correct |
20 |
Correct |
41 ms |
3028 KB |
Output is correct |
21 |
Correct |
38 ms |
3040 KB |
Output is correct |
22 |
Correct |
39 ms |
2876 KB |
Output is correct |
23 |
Correct |
41 ms |
3156 KB |
Output is correct |
24 |
Correct |
42 ms |
3156 KB |
Output is correct |
25 |
Correct |
40 ms |
3124 KB |
Output is correct |
26 |
Correct |
41 ms |
2912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
19 |
Correct |
39 ms |
3020 KB |
Output is correct |
20 |
Correct |
41 ms |
3028 KB |
Output is correct |
21 |
Correct |
38 ms |
3040 KB |
Output is correct |
22 |
Correct |
39 ms |
2876 KB |
Output is correct |
23 |
Correct |
41 ms |
3156 KB |
Output is correct |
24 |
Correct |
42 ms |
3156 KB |
Output is correct |
25 |
Correct |
40 ms |
3124 KB |
Output is correct |
26 |
Correct |
41 ms |
2912 KB |
Output is correct |
27 |
Correct |
43 ms |
3132 KB |
Output is correct |
28 |
Correct |
43 ms |
3140 KB |
Output is correct |
29 |
Correct |
43 ms |
3216 KB |
Output is correct |
30 |
Correct |
41 ms |
3012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
19 |
Correct |
39 ms |
3020 KB |
Output is correct |
20 |
Correct |
41 ms |
3028 KB |
Output is correct |
21 |
Correct |
38 ms |
3040 KB |
Output is correct |
22 |
Correct |
39 ms |
2876 KB |
Output is correct |
23 |
Correct |
41 ms |
3156 KB |
Output is correct |
24 |
Correct |
42 ms |
3156 KB |
Output is correct |
25 |
Correct |
40 ms |
3124 KB |
Output is correct |
26 |
Correct |
41 ms |
2912 KB |
Output is correct |
27 |
Correct |
43 ms |
3132 KB |
Output is correct |
28 |
Correct |
43 ms |
3140 KB |
Output is correct |
29 |
Correct |
43 ms |
3216 KB |
Output is correct |
30 |
Correct |
41 ms |
3012 KB |
Output is correct |
31 |
Correct |
44 ms |
3168 KB |
Output is correct |
32 |
Correct |
43 ms |
3244 KB |
Output is correct |
33 |
Correct |
41 ms |
3156 KB |
Output is correct |
34 |
Correct |
43 ms |
3044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Correct |
2 ms |
456 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
6 ms |
840 KB |
Output is correct |
9 |
Correct |
13 ms |
1352 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
11 |
Correct |
9 ms |
1096 KB |
Output is correct |
12 |
Correct |
13 ms |
1400 KB |
Output is correct |
13 |
Correct |
13 ms |
1352 KB |
Output is correct |
14 |
Correct |
16 ms |
1364 KB |
Output is correct |
15 |
Correct |
43 ms |
3008 KB |
Output is correct |
16 |
Correct |
46 ms |
2964 KB |
Output is correct |
17 |
Correct |
36 ms |
2976 KB |
Output is correct |
18 |
Correct |
39 ms |
2840 KB |
Output is correct |
19 |
Correct |
39 ms |
3020 KB |
Output is correct |
20 |
Correct |
41 ms |
3028 KB |
Output is correct |
21 |
Correct |
38 ms |
3040 KB |
Output is correct |
22 |
Correct |
39 ms |
2876 KB |
Output is correct |
23 |
Correct |
41 ms |
3156 KB |
Output is correct |
24 |
Correct |
42 ms |
3156 KB |
Output is correct |
25 |
Correct |
40 ms |
3124 KB |
Output is correct |
26 |
Correct |
41 ms |
2912 KB |
Output is correct |
27 |
Correct |
43 ms |
3132 KB |
Output is correct |
28 |
Correct |
43 ms |
3140 KB |
Output is correct |
29 |
Correct |
43 ms |
3216 KB |
Output is correct |
30 |
Correct |
41 ms |
3012 KB |
Output is correct |
31 |
Correct |
44 ms |
3168 KB |
Output is correct |
32 |
Correct |
43 ms |
3244 KB |
Output is correct |
33 |
Correct |
41 ms |
3156 KB |
Output is correct |
34 |
Correct |
43 ms |
3044 KB |
Output is correct |
35 |
Correct |
49 ms |
3240 KB |
Output is correct |
36 |
Correct |
46 ms |
3240 KB |
Output is correct |
37 |
Correct |
48 ms |
3272 KB |
Output is correct |
38 |
Correct |
45 ms |
3056 KB |
Output is correct |