# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1121800 | vjudge1 | Unscrambling a Messy Bug (IOI16_messy) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Author: RufatM
#include <bits/stdc++.h>
#include "messy.h"
using namespace std;
#define MOD 1000000007
#define INF 1e9+7
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define pb push_back
#define pii pair<ll,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
string s;
vi perm, ans;
vector<vi> g;
void left(int l, int r) {
if(l == r) return;
int m = (l + r) >> 1;
for(int i = m + 1; i <= r; i++) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
for(int i = m + 1; i <= r; i++) s[i] = '1';
left(l, m);
for(int i = m + 1; i <= r; i++) s[i] = '0';
s[l] = '1';
left(m + 1, r);
s[l] = '0';
}
void right(int id, int l, int r) {
if(l == r) {
perm[l] = g[id].back();
return;
}
int m = (l + r) >> 1;
for(int x : g[id]) {
s[x] = '1';
(check_element(s) ? g[id*2+1] : g[id*2]).pb(x);
s[x] = '0';
}
for(int x : g[id*2+1]) s[x] = '1';
right(id*2, l, m);
for(int x : g[id*2+1]) s[x] = '0';
s[perm[l]] = '1';
right(id*2+1, m + 1, r);
s[perm[l]] = '0';
}
vector<int> restore_permutation(int n, int w, int r) {
s = string(n, '0');
perm.resize(n);
ans.resize(n);
g.resize(4*n);
left(0, n-1);
sett();
g[1].resize(n);
iota(all(g[1]), 0);
right(1, 0, n-1);
for(int i = 0; i < n; i++) ans[perm[i]] = i;
return ans;
}