#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
const int nx=5e4+5;
mt19937 rng(time(0));
int p, c;
vector<int> l, r;
int update(int x)
{
p=Query(x);
swap(c, p);
return c!=p;
}
vector<int> shuffle(vector<int> &x)
{
vector<pair<int, int>> tmp;
vector<int> res(x.size());
for (int i=0; i<x.size(); i++) tmp.push_back({rng(), i});
sort(tmp.begin(), tmp.end());
for (int i=0; i<x.size(); i++) res[i]=x[tmp[i].second];
return res;
}
void solve(vector<int> &l, vector<int> &r, int t)
{
int sz=l.size();
if (sz==1) return Answer(l[0], r[0]), void();
l=shuffle(l);
r=shuffle(r);
int md=(sz-1)/2;
vector<int> l1, l2, r1, r2;
for (int i=0; i<=md; i++) l1.push_back(l[i]), update(l[i]);
for (int i=md+1; i<sz; i++) r1.push_back(l[i]);
for (int i=0; i<sz; i++)
{
if (l2.size()==sz) r2.push_back(r[i]);
else if (r2.size()==sz) l2.push_back(r[i]);
else if (update(r[i])==t) l2.push_back(r[i]);
else r2.push_back(r[i]);
}
solve(l1, l2, !t); solve(r1, r2, t);
}
void Solve(int N) {
for (int i=1; i<=2*N; i++)
{
if (update(i)) l.push_back(i);
else r.push_back(i);
}
solve(l, r, 1);
}
/*
5
4 7
1 2
8 3
6 10
9 5
*/
Compilation message
minerals.cpp: In function 'std::vector<int> shuffle(std::vector<int>&)':
minerals.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i=0; i<x.size(); i++) tmp.push_back({rng(), i});
| ~^~~~~~~~~
minerals.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i=0; i<x.size(); i++) res[i]=x[tmp[i].second];
| ~^~~~~~~~~
minerals.cpp: In function 'void solve(std::vector<int>&, std::vector<int>&, int)':
minerals.cpp:43:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
43 | if (l2.size()==sz) r2.push_back(r[i]);
| ~~~~~~~~~^~~~
minerals.cpp:44:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | else if (r2.size()==sz) l2.push_back(r[i]);
| ~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
7 ms |
600 KB |
Output is correct |
4 |
Correct |
14 ms |
928 KB |
Output is correct |
5 |
Correct |
28 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
19 |
Correct |
100 ms |
2992 KB |
Output is correct |
20 |
Correct |
86 ms |
3012 KB |
Output is correct |
21 |
Correct |
113 ms |
2912 KB |
Output is correct |
22 |
Correct |
89 ms |
3056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
19 |
Correct |
100 ms |
2992 KB |
Output is correct |
20 |
Correct |
86 ms |
3012 KB |
Output is correct |
21 |
Correct |
113 ms |
2912 KB |
Output is correct |
22 |
Correct |
89 ms |
3056 KB |
Output is correct |
23 |
Incorrect |
88 ms |
3028 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
19 |
Correct |
100 ms |
2992 KB |
Output is correct |
20 |
Correct |
86 ms |
3012 KB |
Output is correct |
21 |
Correct |
113 ms |
2912 KB |
Output is correct |
22 |
Correct |
89 ms |
3056 KB |
Output is correct |
23 |
Incorrect |
88 ms |
3028 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
19 |
Correct |
100 ms |
2992 KB |
Output is correct |
20 |
Correct |
86 ms |
3012 KB |
Output is correct |
21 |
Correct |
113 ms |
2912 KB |
Output is correct |
22 |
Correct |
89 ms |
3056 KB |
Output is correct |
23 |
Incorrect |
88 ms |
3028 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
600 KB |
Output is correct |
8 |
Correct |
14 ms |
928 KB |
Output is correct |
9 |
Correct |
28 ms |
1292 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
18 ms |
1036 KB |
Output is correct |
12 |
Correct |
30 ms |
1392 KB |
Output is correct |
13 |
Correct |
29 ms |
1160 KB |
Output is correct |
14 |
Correct |
28 ms |
1136 KB |
Output is correct |
15 |
Correct |
84 ms |
2768 KB |
Output is correct |
16 |
Correct |
97 ms |
2764 KB |
Output is correct |
17 |
Correct |
84 ms |
2752 KB |
Output is correct |
18 |
Correct |
98 ms |
2976 KB |
Output is correct |
19 |
Correct |
100 ms |
2992 KB |
Output is correct |
20 |
Correct |
86 ms |
3012 KB |
Output is correct |
21 |
Correct |
113 ms |
2912 KB |
Output is correct |
22 |
Correct |
89 ms |
3056 KB |
Output is correct |
23 |
Incorrect |
88 ms |
3028 KB |
Wrong Answer [2] |
24 |
Halted |
0 ms |
0 KB |
- |