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 <vector>
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
int sz;
string s="";
vector<int>v[100000];
void add(int l,int r){
if(l+1==r) return;
int m=(l+r)>>1;
for(int i=m+1;i<=r;i++){
s[i]='1';
}
for(int i=l;i<=((l+m)>>1);i++){
s[i]='1';
add_element(s);
// cout << s << '\n';
s[i]='0';
}
for(int i=m+1;i<=r;i++){
s[i]='0';
}
for(int i=l;i<=m;i++){
s[i]='1';
}
for(int i=m+1;i<=((m+r)>>1);i++){
s[i]='1';
add_element(s);
// cout << s << '\n';
s[i]='0';
}
for(int i=l;i<=m;i++){
s[i]='0';
}
add(l,m);
add(m+1,r);
}
void solve(int id,int l,int r){
if(l+1==r) return;
int m=(l+r)>>1;
for(int i:v[id*2+1]){
s[i]='1';
}
for(int i:v[id*2]){
s[i]='1';
if(check_element(s)){
v[id*4].push_back(i);
}
else v[id*4+1].push_back(i);
s[i]='0';
}
for(int i:v[id*2+1]) s[i]='0';
for(int i:v[id*2]) s[i]='1';
for(int i:v[id*2+1]){
s[i]='1';
if(check_element(s)){
v[id*4+2].push_back(i);
}
else v[id*4+3].push_back(i);
s[i]='0';
}
for(int i:v[id*2]) s[i]='0';
solve(id*2,l,m);
solve(id*2+1,m+1,r);
}
vector<int> restore_permutation(int n, int w, int r){
sz=n;
vector<int>ans(n);
for(int i=0;i<n;i++) s+=('0');
for(int i=0;i<(n/2);i++){
s[i]='1';
add_element(s);
s[i]='0';
}
add(0,sz-1);
compile_set();
for(int i=0;i<n;i++){
s[i]='1';
if(check_element(s)){
v[2].push_back(i);
}
else v[3].push_back(i);
s[i]='0';
}
solve(1,0,sz-1);
for(int i=n;i<2*n;i++){
ans[v[i][0]]=i-n;
}
return ans;
}
# | 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... |