#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;
#define ar array
namespace {
const int mxN=500;
int n, ans[2*mxN], nxt[2*mxN], qc, co[2*mxN];
vector<int> adj[2*mxN], vc[2];
bool ba[mxN*2][mxN*2];
}
int qry(vector<int> c) {
/*
for(int &ci : c)
++ci, cerr << ci << " ";
cerr << endl;
*/
for(int &ci : c)
++ci;
++qc;
assert(qc<=2e4);
int a=Query(c);
// cerr << a << endl;
return a;
}
vector<int> gr(int l, int r) {
vector<int> u;
for(int i=l; i<=r; ++i)
u.push_back(i);
return u;
}
vector<int> rv(vector<int> u, vector<int> v) {
for(int vi : v)
if(find(u.begin(), u.end(), vi)!=u.end())
u.erase(find(u.begin(), u.end(), vi));
return u;
}
int fs(int a, vector<int> b, bool sc=0) {
int lb=0, rb=(int)b.size()-1;
while(lb<rb) {
int mb=(lb+rb+1)/2;
vector<int> c(b.begin(), b.begin()+mb);
vector<int> c2=c;
c.push_back(a);
if(sc?qry(c2)+1==qry(c):qry(c)==c.size())
lb=mb;
else
rb=mb-1;
}
return b[lb];
}
/*
void fv2(vector<int> &r, int a, vector<int> b, vector<int> chk, int mx) {
b=rv(b, r);
int it=0;
while(r.size()<mx&&b.size()) {
if(find(chk.begin(), chk.end(), it)!=chk.end()) {
vector<int> c=b;
c.push_back(a);
if(qry(c)==c.size())
break;
}
int u=fs(a, b);
b=rv(b, {u});
r.push_back(u);
// cout << "fv " << u << endl;
// for(int bi : b)
// cout << bi << " ";
// cout << endl;
++it;
}
}
//*/
void fv2(vector<int> &r, int a, vector<int> b) {
b=rv(b, r);
fv3(r, a, b);
}
void fv3(vector<int> &r, int a, vector<int> b, int l1, int r1) {
}
void ua(int a, int b) {
// cerr << "ua " << a << " " << b << endl;
ans[a]=b;
ans[b]=a;
}
void dfs(int u, int c) {
if(~co[u]) {
return;
}
co[u]=c;
vc[co[u]].push_back(u);
for(int v=0; v<2*n; ++v)
if(ba[u][v]||ba[v][u])
dfs(v, c^1);
}
void Solve(int n) {
::n=n;
memset(ans, -1, 4*(2*n));
/*
for(int i=0; i<2*n; ++i) {
if(~ans[i])
continue;
ua(i, fs(i, rv(gr(0, 2*n-1), {i}), 1));
}
*/
//*
//find sexes
/*
for(int i=0; i<2*n; ++i)
for(int j=i+1; j<2*n; ++j)
ba[i][j]=qry({i, j})<2;
*/
/*
for(int i=0; i<n; ++i)
for(int j=n; j<2*n; ++j)
ba[i][j]=1;
//*/
vector<int> pe(2*n);
iota(pe.begin(), pe.end(), 0);
for(int k : {0, 1}) {
random_shuffle(pe.begin(), pe.end());
vector<int> v;
for(int l=0, r=0; r<2*n; ++r) {
bool bd=0;
v.push_back(pe[r]);
while(v.size()>=2&&qry(v)!=v.size()) {
v.erase(v.begin());
++l;
bd=1;
}
if(l&&bd)
ba[pe[l-1]][pe[r]]=1;
}
}
// vector<ar<int, 2>>
memset(co, -1, 4*(2*n));
for(int i=0; i<2*n; ++i)
if(co[i]<0)
dfs(i, 0);
// assert(vc[0].size()==n);
// for(int i=0; i<n; ++i)
// vc[0].push_back(i), vc[1].push_back(i+n);
for(int s=0; s<n; ++s) {
// cerr << "s " << i << endl;
int i=vc[0][s];
if(~ans[i])
continue;
//find related
fv2(adj[i], i, vc[1], {1}, 3);
//add to other nodes
for(int j : adj[i])
if(find(adj[j].begin(), adj[j].end(), i)==adj[j].end())
adj[j].push_back(i);
//if only 1, set to answer
if(adj[i].size()==1) {
ua(i, adj[i][0]);
continue;
}
//if 3...
assert(adj[i].size()==3);
//we can find outgoing edge with 2 queries
if(qry({adj[i][0], adj[i][1], i})==1)
swap(adj[i][2], adj[i][0]);
if(qry({adj[i][0], adj[i][2], i})==1)
swap(adj[i][1], adj[i][0]);
nxt[i]=adj[i][0];
// cerr << "ca " << adj[i][0] << " " << adj[i][1] << " " << adj[i][2] << endl;
for(int j=nxt[i], p=i; ; j=nxt[j]) {
// cerr << "nxt " << j << endl;
// cerr << "ca " << adj[j][0] << " " << adj[j][1] << " " << adj[j][2] << endl;
fv2(adj[j], j, co[j]?vc[0]:vc[1], {}, 3);
assert(adj[j].size()==3);
//add to other nodes
for(int k : adj[j])
if(find(adj[k].begin(), adj[k].end(), j)==adj[k].end())
adj[k].push_back(j);
if(adj[j][0]==p)
swap(adj[j][2], adj[j][0]);
if(adj[j][1]==p)
swap(adj[j][2], adj[j][1]);
// cerr << "ca " << adj[j][0] << " " << adj[j][1] << " " << adj[j][2] << endl;
if(j==i)
break;
if(qry({adj[j][0], adj[j][2], j})==1)
swap(adj[j][1], adj[j][0]);
nxt[j]=adj[j][0];
p=j;
}
for(int j=i; ; j=nxt[j]) {
ua(j, adj[j][1]);
if(nxt[j]==i)
break;
}
}
//*/
for(int i=0; i<2*n; ++i)
if(i<ans[i])
Answer(i+1, ans[i]+1);
}
Compilation message
chameleon.cpp: In function 'int fs(int, std::vector<int>, bool)':
chameleon.cpp:50:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(sc?qry(c2)+1==qry(c):qry(c)==c.size())
~~~~~~^~~~~~~~~~
chameleon.cpp: In function 'void fv2(std::vector<int>&, int, std::vector<int>)':
chameleon.cpp:85:2: error: 'fv3' was not declared in this scope
fv3(r, a, b);
^~~
chameleon.cpp:85:2: note: suggested alternative: 'fv2'
fv3(r, a, b);
^~~
fv2
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:139:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(v.size()>=2&&qry(v)!=v.size()) {
~~~~~~^~~~~~~~~~
chameleon.cpp:133:10: warning: unused variable 'k' [-Wunused-variable]
for(int k : {0, 1}) {
^
chameleon.cpp:162:31: error: too many arguments to function 'void fv2(std::vector<int>&, int, std::vector<int>)'
fv2(adj[i], i, vc[1], {1}, 3);
^
chameleon.cpp:83:6: note: declared here
void fv2(vector<int> &r, int a, vector<int> b) {
^~~
chameleon.cpp:184:43: error: too many arguments to function 'void fv2(std::vector<int>&, int, std::vector<int>)'
fv2(adj[j], j, co[j]?vc[0]:vc[1], {}, 3);
^
chameleon.cpp:83:6: note: declared here
void fv2(vector<int> &r, int a, vector<int> b) {
^~~