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 <bits/stdc++.h>
#include "messy.h"
#define all(x) (x).begin(),(x).end()
using namespace std;
#define sz(x) (int)(x).size()
void divide_in(int l, int r, string hint) {
if(l == r) return;
int mid = l + r >> 1;
for(int i = l; i <= mid; i++) {
hint[i] = '1';
add_element(hint);
hint[i] = '0';
}
for(int i = l; i <= mid; i++)
hint[i] = '1';
divide_in(mid + 1, r, hint);
for(int i = l; i <= mid; i++)
hint[i] = '0',
hint[i - l + mid + 1] = '1';
divide_in(l, mid, hint);
}
vector<int> rez;
void divide_out(int l, int r, string hint) {
//cerr << l << ' ' << r << ' ' << hint << '\n';
if(l == r) {
for(int i = 0; i < sz(hint); i++)
if(hint[i] == '0') {
rez[l] = i;
return;
}
assert(false);
}
int mid = l + r >> 1;
vector<int> lf, rh;
for(int i = 0; i < sz(hint); i++) {
if(hint[i] == '1') continue;
hint[i] = '1';
if(check_element(hint))
//cerr << "L " << hint << '\n',
lf.emplace_back(i);
else
//cerr << "R " << hint << '\n',
rh.emplace_back(i);
hint[i] = '0';
}
for(auto x : rh)
hint[x] = '1';
divide_out(l, mid, hint);
for(auto x : rh)
hint[x] = '0';
for(auto x : lf)
hint[x] = '1';
divide_out(mid + 1, r, hint);
}
vector<int> restore_permutation(int n, int w, int r) {
rez.resize(n);
string hint;
hint.resize(n);
fill(all(hint), '0');
divide_in(0, n - 1, hint);
compile_set();
divide_out(0, n - 1, hint);
vector<int> inv(n);
for(int i = 0; i < sz(rez); i++)
inv[rez[i]] = i;
return inv;
}
Compilation message (stderr)
messy.cpp: In function 'void divide_in(int, int, std::string)':
messy.cpp:12:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
12 | int mid = l + r >> 1;
| ~~^~~
messy.cpp: In function 'void divide_out(int, int, std::string)':
messy.cpp:44:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | int mid = l + r >> 1;
| ~~^~~
# | 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... |