#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,pao=b;i<pao;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
void add_element(std::string x);
bool check_element(std::string x);
void compile_set();
vector<int>ans;
void ins(int l,int m,int r,int n){
string s(n,'0');
fore(i,r+1,n){
s[i]='1';
}
fore(i,0,l){
s[i]='1';
}
fore(i,l,m+1){
s[i]='1';
add_element(s);
s[i]='0';
}
}
void rec1(int l,int r,int n){
if(l==r)return;
int m=(l+r)/2;
ins(l,m,r,n);
rec1(l,m,n);rec1(m+1,r,n);
}
void rec2(int l,int r,int n,vector<int>p){
if(l==r){
ans[p[0]]=l;
return;
}
int n_=SZ(p);
string s(n,'1');
fore(i,0,n_){
s[p[i]]='0';
}
vector<int>pl,pr;
fore(i,0,n_){
s[p[i]]='1';
if(check_element(s)){
pl.push_back(p[i]);
}else{
pr.push_back(p[i]);
}
s[p[i]]='0';
}
int m=(l+r)/2;
rec2(l,m,n,pl);rec2(m+1,r,n,pr);
}
std::vector<int> restore_permutation(int n, int w, int r){
rec1(0,n-1,n);
compile_set();
ans.resize(n);
vector<int>p(n);
iota(ALL(p),0);
rec2(0,n-1,n,p);
return ans;
}
Compilation message (stderr)
messy.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
messy_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~| # | 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... |