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>
using namespace std;
#include "messy.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
#define fi first
#define se second
#define pb emplace_back
#define ll long long
#define INF 1023456789
#define INFll 1023456789123456789
#define all(x) x.begin(), x.end()
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
vector<int> ans;
vector<int> s[135];
char st[7];
void add(int n, int l, int r, vector<int> v){
if (l == r - 1) return;
int m = (l + r) / 2;
for (int i = l; i < m; ++i){
string s;
s.append(n, '0');
s[i] = '1';
for (int x: v) s[x] = '1';
add_element(s);
}
{
vector<int> t = v;
for (int i = l; i < m; ++i) t.pb(i);
add(n, m, r, t);
}
{
vector<int> t = v;
for (int i = m; i < r; ++i) t.pb(i);
add(n, l, m, t);
}
}
void solve(int n, int l, int r, vector<int> c, vector<int> tr, vector<int> id){
if (l == r - 1){
ans[c[0]] = l; return;
}
vector<int> lc, rc;
for (int x: c){
string s;
s.append(n, '0');
for (int i: id) s[i] = '1';
s[x] = '1';
if (check_element(s)) lc.pb(x);
else rc.pb(x);
}
int m = (l + r) / 2;
{
vector<int> t = tr;
vector<int> tid = id;
for (int i: lc) tid.pb(i);
for (int i = l; i < m; ++i) t.pb(i);
solve(n, m, r, rc, t, tid);
}
{
vector<int> t = tr;
vector<int> tid = id;
for (int i: rc) tid.pb(i);
for (int i = m; i < r; ++i) t.pb(i);
solve(n, l, m, lc, t, tid);
}
}
std::vector<int> restore_permutation(int n, int w, int r) {
add(n, 0, n, vector<int>());
compile_set();
ans.resize(n);
vector<int> v;
for (int i = 0; i < n; ++i) v.pb(i);
solve(n, 0, n, v, vector<int>(), vector<int>());
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... |