#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
mt19937 rng((ll)chrono::steady_clock::now().time_since_epoch().count());
random_device rd;
mt19937 g(rd());
ll rnd(ll u, ll v){
return uniform_int_distribution<ll>(u,v)(rng);
}
int mp[86005];
bool used[86005];
int cnt=0;
int machine=0;
bool inside[86005];
map<ll,ll>hv;
int query_num=0;
ll fp[43005],sp[43005];
bool pref[86005];
ll timer=1,timer2=1;
void dc(ll l, ll r){
if(l==r)return;
ll mid=(l+r-1)>>1;
if(mid>=l+2400)mid-=1080;
else if(mid>=l+1200)mid-=540;
else if(mid>=l+610)mid-=275;
else if(mid>=l+308)mid-=137;
else if(mid>=l+154)mid-=60;
else if(mid>=l+76)mid-=30;
else if(mid>=l+72)mid-=29;
else if(mid>=l+68)mid-=28;
else if(mid>=l+64)mid-=27;
else if(mid>=l+56)mid-=23;
else if(mid>=l+52)mid-=21;
else if(mid>=l+50)mid-=19;
else if(mid>=l+44)mid-=17;
else if(mid>=l+40)mid-=13;
else if(mid>=l+38)mid-=10;
else if(mid>=l+30)mid-=8;
else if(mid>=l+24)mid-=7;
else if(mid>=l+20)mid-=6;
else if(mid>=l+17)mid-=5;
else if(mid>=l+13)mid-=4;
else if(mid>=l+10)mid-=3;
else if(mid>=l+8)mid-=2;
else if(mid>=l+2)mid--;
ll last_qry;
bool noonlef=0;
for(int i=l;i<=mid;i++){
last_qry=Query(fp[i]); pref[fp[i]]^=1;
if(pref[fp[i]]==0)noonlef=1;
}
// cout<<"dc "<<l<<" "<<r<<" "<<noonlef<<'\n';
vector<ll>lef,righ;
ll brkid;
for(int i=l;i<=r-1;i++){
ll curq=Query(sp[i]);
pref[sp[i]]^=1;
bool remov=0;
if(!pref[sp[i]])remov=1;
if(remov){
if(curq==last_qry){
if(noonlef)righ.push_back(sp[i]);
else lef.push_back(sp[i]);
}
else{
if(noonlef)lef.push_back(sp[i]);
else righ.push_back(sp[i]);
}
}
else{
if(curq==last_qry){
if(noonlef)righ.push_back(sp[i]);
else lef.push_back(sp[i]);
}
else{
if(noonlef)lef.push_back(sp[i]);
else righ.push_back(sp[i]);
}
}
if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
brkid=i; break;
}
last_qry=curq;
}
if(lef.size()!=mid-l+1){
for(int i=brkid+1;i<=r;i++){
lef.push_back(sp[i]);
}
}
else{
for(int i=brkid+1;i<=r;i++){
righ.push_back(sp[i]);
}
}
shuffle(lef.begin(),lef.end(),g);
shuffle(righ.begin(),righ.end(),g);
for(int i=0;i<lef.size();i++){
sp[l+i]=lef[i];
}
for(int i=0;i<righ.size();i++){
sp[mid+1+i]=righ[i];
}
dc(l,mid); dc(mid+1,r);
}
void Solve(ll n){
int prev=0;
for(int i=1;i<=2*n;i++){
int cur=Query(i);
if(cur==prev+1){
fp[timer++]=i;
}
else{
sp[timer2++]=i;
}
prev=cur;
}
for(int i=1;i<=2*n;i++)pref[i]=1;
dc(1,n);
for(int i=1;i<=n;i++){
Answer(fp[i],sp[i]);
}
}
Compilation message
minerals.cpp: In function 'void dc(long long int, long long int)':
minerals.cpp:84:22: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
84 | if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
| ~~~~~~~~~~^~~~~~~~~
minerals.cpp:84:44: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
84 | if(lef.size()==mid-l+1||righ.size()==r-(mid+1)+1){
| ~~~~~~~~~~~^~~~~~~~~~~~~
minerals.cpp:89:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
89 | if(lef.size()!=mid-l+1){
| ~~~~~~~~~~^~~~~~~~~
minerals.cpp:101:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for(int i=0;i<lef.size();i++){
| ~^~~~~~~~~~~
minerals.cpp:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for(int i=0;i<righ.size();i++){
| ~^~~~~~~~~~~~
minerals.cpp:95:24: warning: 'brkid' may be used uninitialized in this function [-Wmaybe-uninitialized]
95 | for(int i=brkid+1;i<=r;i++){
| ~~~~~^~
minerals.cpp:65:13: warning: 'last_qry' may be used uninitialized in this function [-Wmaybe-uninitialized]
65 | if(curq==last_qry){
| ^~
/usr/bin/ld: /tmp/ccTJ0SWz.o: in function `main':
grader.cpp:(.text.startup+0xbd): undefined reference to `Solve(int)'
collect2: error: ld returned 1 exit status