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>
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef pair <ll,ll> pi;
typedef vector <int> vec;
const ll INF = 1e18;
int n;
vec ans;
void build(int l,int r) {
if(l == r) return;
int mid = (l + r) >> 1;
string p;
for(int i = 0;i < l;i++) p += "1";
for(int i = l;i <= r;i++) p += "0";
for(int i = r+1;i < n;i++) p += "1";
for(int i = l;i <= mid;i++) {
p[i] = '1';
//cout << p << '\n';
add_element(p);
p[i] = '0';
}
build(l,mid), build(mid+1,r);
}
void go(vec x,int l,int r) {
if(l == r) {
ans[x[0]] = l; return;
}
string p;
for(int i = 0;i < n;i++) p += "1";
for(int i : x) p[i] = '0';
vec ne[2];
for(int i : x) {
p[i] = '1';
ne[(int)check_element(p)].push_back(i);
p[i] = '0';
}
int mid = (l + r) >> 1;
go(ne[1],l,mid), go(ne[0],mid+1,r);
}
vec restore_permutation(int N,int w,int r) {
n = N;
build(0,n-1);
compile_set();
ans.resize(n);
vec tmp;
for(int i = 0;i < n;i++) tmp.push_back(i);
go(tmp,0,n-1);
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... |