This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include "library.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
vector<int> res;
set<int> rem;
int n;
int query(vector<int> &test)
{
int ex1=0;
for(int i=0;i<n;i++)
{
if(test[i]) ex1=1;
}
if(!ex1) return 0;
else return Query(test);
}
void solve(int l, int r)
{
//cerr<<"SOLVE "<<l<<' '<<r<<'\n';
if(l>r) return ;
if(l==r)
{
res[l] = (*rem.begin()); return ;
}
int xr=0;
for(int i=0;i<10;i++)
{
vector<int> test(n,0);
for(int x:rem)
{
if(x&(1<<i))
{
test[x]=1;
}
}
int res = query(test);
test.assign(n,0);
for(int x:rem)
{
if(!(x&(1<<i)))
{
test[x]=1;
}
}
int res2 = query(test);
if(res==res2)
{
xr^=(1<<i);
}
}
set<int> possibleX; vi V;
for(int x:rem)
{
if(possibleX.find(x^xr)==possibleX.end())
{
possibleX.insert(x); V.pb(x);
}
}
int lo=0; int hi=int(V.size())-1;
int ans = -1;
while(lo<=hi)
{
int mid=(lo+hi)>>1;
vector<int> test(n,0);
for(int i=0;i<V.size();i++)
{
if(i<=mid) test[V[i]]=1;
else test[V[i]]=0;
}
int ans1 = query(test);
for(int x:rem)
{
test[x]^=1;
}
int ans2=query(test);
if(ans1==ans2)
{
ans=mid;
hi=mid-1;
}
else lo=mid+1;
}
//cerr<<"XOR : "<<xr<<'\n'; //cerr<<"ANS : "<<ans<<'\n';
int x = V[ans]; int y = V[ans]^xr;
if(l>0)
{
vector<int> test(n,0);
test[res[l-1]]=1; test[x]=1;
if(query(test)!=1)
{
swap(x,y);
}
}
res[l] = x; res[r] = y;
//cerr<<l<<' '<<x<<'\n'; //cerr<<r<<' '<<y<<'\n';
rem.erase(x); rem.erase(y);
solve(l+1,r-1);
}
void Solve(int N)
{
n=N;
res.resize(N);
for(int i=0;i<N;i++) rem.insert(i);
solve(0,N-1);
for(int i=0;i<N;i++) res[i]++;
Answer(res);
}
Compilation message (stderr)
library.cpp: In function 'void solve(int, int)':
library.cpp:89:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<V.size();i++)
~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |