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 "perm.h"
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ioi exit(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
ll n;
vector<int>ans, tmp, was;
vector<vector<int>> g;
void go(ll x) {
if (!x) return;
if (x & 1) {
go(x / 2);
ans.pb(sz(ans) ? *max_element(all(ans)) + 1 : 0);
}
else {
go(x - 1);
ans.pb(sz(ans) ? *min_element(all(ans)) - 1 : 0);
}
}
void dfs(int v) {
was[v] = 1;
for (auto to : g[v]) if (!was[to]) dfs(to);
tmp.pb(v);
}
void solve(ll n) {
// cin >> n;
ans.clear();
g.clear();
tmp.clear();
was.clear();
go(n-1);
g.resize(sz(ans));
was.resize(sz(ans));
rep(i, 0, sz(ans) - 1) {
// cerr << ans[i] << ' ';
rep(j, i + 1, sz(ans) - 1) {
if (ans[i] < ans[i]) {
g[j].pb(i);
}
if (ans[i] > ans[j]) {
g[i].pb(j);
}
}
}
// cerr << nl;
rep(i, 0, sz(ans) - 1) if (!was[i]) dfs(i);
}
vector<int> construct_permutation(ll n) {
solve(n);
// reverse(all(tmp));
vector<int> perm(sz(tmp));
rep(i, 0, sz(tmp) - 1) perm[tmp[i]] = i;
return perm;
// for (auto it : tmp) cout << it << ' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |