#include"minerals.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int>arr;
bool alive[100015],vis[100015];
const int C=19;
int n;
void brute(vector<int>arr1,vector<int>arr2,bool stay){
stay^=1;
shuffle(arr1.begin(),arr1.end(),rng);
shuffle(arr2.begin(),arr2.end(),rng);
// cout<<"Brute : \n";
// for (auto i:arr1) cout<<i<<" ";
// cout<<'\n';
// for (auto i:arr2) cout<<i<<' ';
// cout<<'\n';
int sz=arr1.size();
for (auto i:arr2){
int last=Query(i),use=0;
shuffle(arr1.begin(),arr1.end(),rng);
for (auto j:arr1){
if (vis[j]) continue;
if (use==sz-1){
Answer(i,j);
break;
}
alive[j]^=1;
int now=Query(j);
if (stay==1){
if (now==last){
// cout<<"match1 "<<i<<" "<<j<<'\n';
Answer(i,j);
vis[j]=1;
break;
}
}
else {
if (now!=last){
// cout<<"match2 "<<i<<" "<<j<<'\n';
Answer(i,j);
vis[j]=1;
break;
}
}
last=now;
}
sz--;
}
}
void Merge(int l,int r,vector<int>have,bool stay1,bool stay2){
if (r-l+1<=C){
vector<int>now;
for (int i=l-1;i<r;i++)
now.push_back(arr[i]);
brute(now,have,stay2);
return;
}
/*
if (l==r){
Answer(arr[l-1],have[0]);
return;
}
*/
int mid=(l+r)>>1,last;
vector<int>L,R;
if (!stay1){
for (int i=l-1;i<mid;i++){
last=Query(arr[i]);
alive[arr[i]]^=1;
}
}
else {
for (int i=mid;i<r;i++){
last=Query(arr[i]);
alive[arr[i]]^=1;
}
}
for (auto i:have){
int now=Query(i);
alive[i]^=1;
bool ty=(now==last);
if (ty)
L.push_back(i);
else R.push_back(i);
last=now;
}
Merge(mid+1,r,R,0,stay2^1);
Merge(l,mid,L,1,stay2^1);
}
void Solve(int N){
n=N;
vector<int>qry;
int last=-1;
for (int i=1;i<=2*N;i++){
int now=Query(i);
if (now==last){
qry.push_back(i);
}
else {
arr.push_back(i);
last=now;
}
alive[i]=1;
}
//for (auto i:arr) cout<<i<<" ";
//cout<<'\n';
//for (auto i:qry) cout<<i<<" ";
//cout<<'\n';
Merge(1,N,qry,1,1);
}
/*
g++ -std=gnu++14 -O2 -o grader grader.cpp minerals.cpp
./grader.exe
./rand.exe
4
1 5
2 6
3 4
7 8
*/
Compilation message
minerals.cpp: In function 'void Merge(int, int, std::vector<int>, bool, bool)':
minerals.cpp:83:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | if (ty)
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
3 ms |
436 KB |
Output is correct |
3 |
Correct |
4 ms |
464 KB |
Output is correct |
4 |
Correct |
7 ms |
720 KB |
Output is correct |
5 |
Correct |
15 ms |
1104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
19 |
Correct |
37 ms |
2636 KB |
Output is correct |
20 |
Correct |
42 ms |
2632 KB |
Output is correct |
21 |
Correct |
33 ms |
2612 KB |
Output is correct |
22 |
Correct |
34 ms |
2380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
19 |
Correct |
37 ms |
2636 KB |
Output is correct |
20 |
Correct |
42 ms |
2632 KB |
Output is correct |
21 |
Correct |
33 ms |
2612 KB |
Output is correct |
22 |
Correct |
34 ms |
2380 KB |
Output is correct |
23 |
Correct |
42 ms |
2732 KB |
Output is correct |
24 |
Correct |
38 ms |
2708 KB |
Output is correct |
25 |
Correct |
37 ms |
2664 KB |
Output is correct |
26 |
Correct |
32 ms |
2468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
19 |
Correct |
37 ms |
2636 KB |
Output is correct |
20 |
Correct |
42 ms |
2632 KB |
Output is correct |
21 |
Correct |
33 ms |
2612 KB |
Output is correct |
22 |
Correct |
34 ms |
2380 KB |
Output is correct |
23 |
Correct |
42 ms |
2732 KB |
Output is correct |
24 |
Correct |
38 ms |
2708 KB |
Output is correct |
25 |
Correct |
37 ms |
2664 KB |
Output is correct |
26 |
Correct |
32 ms |
2468 KB |
Output is correct |
27 |
Correct |
36 ms |
2732 KB |
Output is correct |
28 |
Correct |
36 ms |
2796 KB |
Output is correct |
29 |
Correct |
30 ms |
2752 KB |
Output is correct |
30 |
Correct |
31 ms |
2564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
19 |
Correct |
37 ms |
2636 KB |
Output is correct |
20 |
Correct |
42 ms |
2632 KB |
Output is correct |
21 |
Correct |
33 ms |
2612 KB |
Output is correct |
22 |
Correct |
34 ms |
2380 KB |
Output is correct |
23 |
Correct |
42 ms |
2732 KB |
Output is correct |
24 |
Correct |
38 ms |
2708 KB |
Output is correct |
25 |
Correct |
37 ms |
2664 KB |
Output is correct |
26 |
Correct |
32 ms |
2468 KB |
Output is correct |
27 |
Correct |
36 ms |
2732 KB |
Output is correct |
28 |
Correct |
36 ms |
2796 KB |
Output is correct |
29 |
Correct |
30 ms |
2752 KB |
Output is correct |
30 |
Correct |
31 ms |
2564 KB |
Output is correct |
31 |
Incorrect |
37 ms |
2840 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
3 ms |
436 KB |
Output is correct |
7 |
Correct |
4 ms |
464 KB |
Output is correct |
8 |
Correct |
7 ms |
720 KB |
Output is correct |
9 |
Correct |
15 ms |
1104 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
10 ms |
848 KB |
Output is correct |
12 |
Correct |
13 ms |
1232 KB |
Output is correct |
13 |
Correct |
14 ms |
1136 KB |
Output is correct |
14 |
Correct |
14 ms |
1068 KB |
Output is correct |
15 |
Correct |
39 ms |
2636 KB |
Output is correct |
16 |
Correct |
38 ms |
2632 KB |
Output is correct |
17 |
Correct |
32 ms |
2560 KB |
Output is correct |
18 |
Correct |
33 ms |
2384 KB |
Output is correct |
19 |
Correct |
37 ms |
2636 KB |
Output is correct |
20 |
Correct |
42 ms |
2632 KB |
Output is correct |
21 |
Correct |
33 ms |
2612 KB |
Output is correct |
22 |
Correct |
34 ms |
2380 KB |
Output is correct |
23 |
Correct |
42 ms |
2732 KB |
Output is correct |
24 |
Correct |
38 ms |
2708 KB |
Output is correct |
25 |
Correct |
37 ms |
2664 KB |
Output is correct |
26 |
Correct |
32 ms |
2468 KB |
Output is correct |
27 |
Correct |
36 ms |
2732 KB |
Output is correct |
28 |
Correct |
36 ms |
2796 KB |
Output is correct |
29 |
Correct |
30 ms |
2752 KB |
Output is correct |
30 |
Correct |
31 ms |
2564 KB |
Output is correct |
31 |
Incorrect |
37 ms |
2840 KB |
Wrong Answer [2] |
32 |
Halted |
0 ms |
0 KB |
- |