#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];
const int C=20;
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);
bool vis[30]={0};
for (int i=0;i<30;i++)
vis[i]=0;
for (auto i:arr2){
int last=Query(i);
for (auto j:arr1){
if (vis[j]) continue;
alive[j]^=1;
int now=Query(j);
if (stay==1){
if (now==last){
Answer(i,j);
vis[j]=1;
break;
}
}
else {
if (now!=last){
Answer(i,j);
vis[j]=1;
break;
}
}
}
}
}
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;
}
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
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:65:9: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
65 | if (ty)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |