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 pb push_back
vector<int> restore_permutation(int n, int w, int r)
{
const auto build = [&](const auto &self, int l, int r) -> void
{
if (l == r)
return;
int mid = (l + r) >> 1;
for (int i = l; i <= mid; ++i)
{
string s = string(l, '1') + string(r-l+1, '0') + string(n-r-1, '1');
s[i] = '1';
add_element(s);
}
self(self, l, mid);
self(self, mid+1, r);
};
build(build, 0, n-1);
compile_set();
vector<int> res(n);
iota(res.begin(), res.end(), 0);
const auto solve = [&](const auto &self, int l, int r) -> void
{
if (l == r)
return;
int mid = (l + r) >> 1;
string s = string(n, '0');
for (int i = 0; i < l; ++i)
s[res[i]] = '1';
for (int i = r+1; i < n; ++i)
s[res[i]] = '1';
vector<int> lt, rt;
for (int i = l; i <= r; ++i)
{
s[res[i]] = '1';
if (check_element(s))
lt.pb(res[i]);
else rt.pb(res[i]);
s[res[i]] = '0';
}
for (int i = l; i <= mid; ++i)
res[i] = lt[i-l];
for (int i = mid+1; i <= r; ++i)
res[i] = rt[i-mid-1];
self(self, l, mid);
self(self, mid+1, r);
};
solve(solve, 0, n-1);
vector<int> tmp(n);
for (int i = 0; i < n; ++i)
tmp[res[i]] = i;
return tmp;
}
# | 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... |