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;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
int n;
/*
add_element("0");
compile_set();
check_element("0");
*/
string s;
void build(int l, int r){
int mid=(l+r)>>1ll;
for(int i=l; i<=mid; i++){
s[i-1]='1';
add_element(s);
s[i-1]='0';
}
if(l==r){
return ;
}
//construiect partea dreapta, partea stanga fiind complet acoperita
for(int i=l; i<=mid; i++){
s[i-1]='1';
}
build(mid+1, r);
//construiesc partea stanga, partea dreapta fiind total acoperita
for(int i=l; i<=mid; i++){
s[i-1]='0';
}
build(l, mid);
}
vector<int> seg[1001];
void build_seg(int v, int tl, int tr){
if(tl==(tr-1) ){
for(int i=0; i<n; i++){
if(s[i]=='0'){
s[i]='1';
bool res=check_element(s);
if(res){
seg[2*v].pb(i+1);
}
s[i]='0';
}
}
return ;
}
int mid=(tl+tr)>>1ll;
for(int i=0; i<n; i++){
if(s[i]=='0'){
s[i]='1';
bool res=check_element(s);
if(res){
seg[2*v].pb(i+1);
}
s[i]='0';
}
}
for(auto i:seg[2*v]){
s[i-1]='1';
}
for(int i=0; i<n; i++){
if(s[i]=='0'){
seg[2*v+1].pb(i+1);
}
}
build_seg(v*2+1, mid+1, tr);
for(auto i:seg[2*v]){
s[i-1]='0';
}
build_seg(2*v, tl, mid);
}
void nulify(){
for(int i=0; i<n; i++){
s[i]='0';
}
}
vector<int> res;
void get_all(int v, int l, int r){
if(l==r){
res[l-1]=seg[v][0];
return;
}
get_all(v*2, l, (l+r)>>1ll);
get_all(2*v+1, ((l+r)>>1ll)+1, r);
return;
}
std::vector<int> restore_permutation(int N, int w, int r) {
n=N;
s.resize(n);
for(int i=0; i<n; i++){
s[i]='0';
}
build(1, n);
compile_set();
nulify();
build_seg(1, 1, n);
res.resize(n);
get_all(1, 1, n);
return res;
}
# | 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... |