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 "messy.h"
#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> ans;
void genQuery(int st, int dr)
{
if(st == dr)
return;
int mij=(st+dr)/2;
for(int i=st; i<=mij; i++)
{
s[i]='1';
//cout<<s<<'\n';
add_element(s);
s[i]='0';
}
for(int i=mij+1; i<=dr; i++)
s[i]='1';
genQuery(st, mij);
for(int i=mij+1; i<=dr; i++)
s[i]='0';
for(int i=st; i<=mij; i++)
s[i]='1';
genQuery(mij+1, dr);
}
void genAns(int st, int dr, vector<int> v)
{
/*
cout<<st<<' '<<dr<<":\n";
for(int it : v)
cout<<it<<' ';
cout<<"\n\n";
*/
if(st == dr)
{
ans[ v[0] ] = st;
return;
}
int mij=(st+dr)/2;
vector<int> vL, vR;
for(int it : v)
{
s[it]='1';
//cout<<"query "<<s<<' ';
if(check_element(s))
{
//cout<<"da\n";
vL.push_back(it);
}
else
{
//cout<<"nu\n";
vR.push_back(it);
}
s[it]='0';
}
//cout<<'\n';
for(int it : vR)
s[it]='1';
genAns(st, mij, vL);
for(int it : vR)
s[it]='0';
for(int it : vL)
s[it]='1';
genAns(mij+1, dr, vR);
}
vector<int> restore_permutation(int n, int w, int r)
{
s.resize(n);
ans.resize(n);
for(int i=0; i<n; i++)
s[i]='0';
genQuery(0, n-1);
compile_set();
for(int i=0; i<n; i++)
s[i]='0';
vector<int> aux;
for(int i=0;i<n;i++)
aux.push_back(i);
genAns(0, n-1, aux);
return ans;
}
/*
8 24 24
0 1 7 5 2 4 3 6
*/
# | 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... |