#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
mt19937 rng(323);
int gen(int m){
return ((int)rng() % m + m) % m;
}
int las;
vector<pii> ans;
set<int> E;
int ask(int id){
if(E.count(id)) E.erase(id);
else E.insert(id);
int res = Query(id);
return res;
}
void shuffle(vector<int> &ord){
for(int i = 0 ; i < ord.size(); i ++ ){
swap(ord[i], ord[gen(i + 1)]);
}
}
void pair_up(vector<int> A, vector<int> B, bool in_a, bool in_b){
if(A.empty()) return;
if(A.size() == 1){
ans.push_back(mp(A[0], B[0]));
return;
}
shuffle(A);
shuffle(B);
int mid = (int)A.size() / 2;
vector<int> a0, a1;
bool ia0 = in_a, ia1 = in_a;
bool ib0 = in_b, ib1 = in_b;
vector<int> b0, b1;
for(int i = 0 ; i < mid; i ++ ){
int cur = ask(A[i]);
las=cur;
a0.push_back(A[i]);
}
ia0 ^= 1;
for(int i = mid ; i < A.size(); i ++ ){
a1.push_back(A[i]);
}
ib0 ^= 1;
for(auto x : B){
int cur = ask(x);
if(cur == las){
if(ia0) b0.push_back(x);
else b1.push_back(x);
}
else{
if(ia0) b1.push_back(x);
else b0.push_back(x);
}
las = cur;
}
pair_up(a0, b0, ia0, ib0);
pair_up(a1, b1, ia1, ib1);
}
void Solve(int n) {
las = 0;
ans.clear();
vector<int> ord;
for(int i = 1; i <= 2 * n; i ++ ){
ord.push_back(i);
}
shuffle(ord);
vector<int> aa, bb;
for(auto x : ord){
int cur = ask(x);
if(cur != las){
aa.push_back(x);
}
else{
bb.push_back(x);
}
las = cur;
}
pair_up(aa, bb, true, true);
for (auto x : ans)
Answer(x.fi, x.se);
}
Compilation message
minerals.cpp: In function 'void shuffle(std::vector<int>&)':
minerals.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 0 ; i < ord.size(); i ++ ){
| ~~^~~~~~~~~~~~
minerals.cpp: In function 'void pair_up(std::vector<int>, std::vector<int>, bool, bool)':
minerals.cpp:55:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for(int i = mid ; i < A.size(); i ++ ){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
464 KB |
Output is correct |
2 |
Correct |
8 ms |
592 KB |
Output is correct |
3 |
Correct |
19 ms |
976 KB |
Output is correct |
4 |
Correct |
42 ms |
1628 KB |
Output is correct |
5 |
Correct |
94 ms |
3016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
19 |
Correct |
307 ms |
7476 KB |
Output is correct |
20 |
Correct |
312 ms |
7500 KB |
Output is correct |
21 |
Correct |
294 ms |
7512 KB |
Output is correct |
22 |
Correct |
301 ms |
7348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
19 |
Correct |
307 ms |
7476 KB |
Output is correct |
20 |
Correct |
312 ms |
7500 KB |
Output is correct |
21 |
Correct |
294 ms |
7512 KB |
Output is correct |
22 |
Correct |
301 ms |
7348 KB |
Output is correct |
23 |
Correct |
308 ms |
7644 KB |
Output is correct |
24 |
Correct |
315 ms |
7728 KB |
Output is correct |
25 |
Correct |
323 ms |
7696 KB |
Output is correct |
26 |
Correct |
310 ms |
7488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
19 |
Correct |
307 ms |
7476 KB |
Output is correct |
20 |
Correct |
312 ms |
7500 KB |
Output is correct |
21 |
Correct |
294 ms |
7512 KB |
Output is correct |
22 |
Correct |
301 ms |
7348 KB |
Output is correct |
23 |
Correct |
308 ms |
7644 KB |
Output is correct |
24 |
Correct |
315 ms |
7728 KB |
Output is correct |
25 |
Correct |
323 ms |
7696 KB |
Output is correct |
26 |
Correct |
310 ms |
7488 KB |
Output is correct |
27 |
Incorrect |
324 ms |
7804 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
19 |
Correct |
307 ms |
7476 KB |
Output is correct |
20 |
Correct |
312 ms |
7500 KB |
Output is correct |
21 |
Correct |
294 ms |
7512 KB |
Output is correct |
22 |
Correct |
301 ms |
7348 KB |
Output is correct |
23 |
Correct |
308 ms |
7644 KB |
Output is correct |
24 |
Correct |
315 ms |
7728 KB |
Output is correct |
25 |
Correct |
323 ms |
7696 KB |
Output is correct |
26 |
Correct |
310 ms |
7488 KB |
Output is correct |
27 |
Incorrect |
324 ms |
7804 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
464 KB |
Output is correct |
6 |
Correct |
8 ms |
592 KB |
Output is correct |
7 |
Correct |
19 ms |
976 KB |
Output is correct |
8 |
Correct |
42 ms |
1628 KB |
Output is correct |
9 |
Correct |
94 ms |
3016 KB |
Output is correct |
10 |
Correct |
4 ms |
464 KB |
Output is correct |
11 |
Correct |
66 ms |
2164 KB |
Output is correct |
12 |
Correct |
95 ms |
3088 KB |
Output is correct |
13 |
Correct |
91 ms |
2996 KB |
Output is correct |
14 |
Correct |
93 ms |
2924 KB |
Output is correct |
15 |
Correct |
305 ms |
7308 KB |
Output is correct |
16 |
Correct |
293 ms |
7340 KB |
Output is correct |
17 |
Correct |
282 ms |
7304 KB |
Output is correct |
18 |
Correct |
296 ms |
7248 KB |
Output is correct |
19 |
Correct |
307 ms |
7476 KB |
Output is correct |
20 |
Correct |
312 ms |
7500 KB |
Output is correct |
21 |
Correct |
294 ms |
7512 KB |
Output is correct |
22 |
Correct |
301 ms |
7348 KB |
Output is correct |
23 |
Correct |
308 ms |
7644 KB |
Output is correct |
24 |
Correct |
315 ms |
7728 KB |
Output is correct |
25 |
Correct |
323 ms |
7696 KB |
Output is correct |
26 |
Correct |
310 ms |
7488 KB |
Output is correct |
27 |
Incorrect |
324 ms |
7804 KB |
Wrong Answer [2] |
28 |
Halted |
0 ms |
0 KB |
- |