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"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;
void prepare(int n, vector<int> cand, int lvl) {
    if(lvl < 0) return;
    string s;
    For(i, 1, n) s.push_back('1');
    for(auto &i:cand) s[i] = '0';
    vector<int> c1, c0;
    for(auto &i:cand) {
        if(i & (1 << lvl)) {
            s[i] = '1';
            add_element(s);
            s[i] = '0';
            c1.eb(i);
        } else {
            c0.eb(i);
        }
    }
    prepare(n, c0, lvl - 1);
    prepare(n, c1, lvl - 1);
}
void solve(int n, vector<int> cand, int lvl, int mask, vector<int> &ans) {
    if(lvl < 0) {
        // for(auto &i:cand) cerr << i << " ";
        // cerr << "?????\n";
        ans[cand[0]] = mask;
        return;
    }
    string s;
    For(i, 1, n) s.push_back('1');
    for(auto &i:cand) s[i] = '0';
    vector<int> c1, c0;
    for(auto &i:cand) {
        s[i] = '1';
        if(check_element(s)) c1.eb(i);
        else c0.eb(i);
        s[i] = '0';
    }
    solve(n, c0, lvl - 1, mask, ans);
    solve(n, c1, lvl - 1, mask | (1 << lvl), ans);
}
vector<int32_t> restore_permutation(int32_t n, int32_t w, int32_t r) {
    int lg = __lg(n);
    vector<int> v(n);
    For(i, 0, n - 1) v[i] = i;
    prepare(n, v, lg - 1);
    compile_set();
    vector<int> ans(n);
    solve(n, v, lg - 1, 0, ans);
    return vector<int32_t>(all(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... |