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 <bits/stdc++.h>
#define ll long long
#define db long double
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#include "messy.h"
using namespace std;
/*
struct Interactive
{
int n=4,p[4]={ 2,1,3,0 };
map <string,bool> have;
void add(string a)
{
string s="";
for(int i=0;i<n;i++) s+=a[p[i]];
have[s]=1;
}
bool check(string s) { return have[s]; }
} IR;
void add_element(string s) { IR.add(s); }
bool check_element(string s) { return IR.check(s); }
*/
int n,a[100005];
void Add(int l,int r)
{
if(l==r) return ;
int mid=(l+r)>>1,i;
string s="";
for(i=0;i<n;i++) s+="0";
for(i=0;i<n;i++)
if(i<l || i>r) s[i]='1';
for(i=l;i<=mid;i++)
{
s[i]='1';
add_element(s);
s[i]='0';
}
Add(l,mid); Add(mid+1,r);
}
void Fill(int l,int r,vector <int> our)
{
if(l==r) { a[our[0]]=l; return ; }
vector <int> v1,v2;
map <int,bool> have;
for(int i:our) have[i]=1;
string s="";
int mid=(l+r)>>1,i;
for(i=0;i<n;i++) s+="0";
for(i=0;i<n;i++)
if(have[i]==0) s[i]='1';
for(int i:our)
{
s[i]='1';
if(check_element(s)) v1.push_back(i);
else v2.push_back(i);
s[i]='0';
}
Fill(l,mid,v1); Fill(mid+1,r,v2);
}
vector <int> restore_permutation(int _n,int w,int r)
{
n=_n;
vector <int> vec,p;
Add(0,n-1);
compile_set();
for(int i=0;i<n;i++) vec.push_back(i);
Fill(0,n-1,vec);
for(int i=0;i<n;i++) p.push_back(a[i]);
return p;
}
/*
int main()
{
freopen("messy.inp","r",stdin);
freopen("messy.out","w",stdout);
int n,w,r,p[105],i;
cin>>n>>w>>r;
restore_permutation(n,w,r,p);
for(i=0;i<n;i++) cout<<p[i]<<" ";
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |