This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
#include "swaps.h"
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 505;
const int MAXL = 9;
int n, on;
vi p;
vii moves;
void my_schedule(int i, int j) {
cerr << " " << i << ' ' << j << '\n';
moves.pb({i, j});
if (i <= on && j <= on) {
schedule(i, j);
}
}
vi my_visit() {
vi tmp = visit();
reverse(ALL(tmp));
vi res;
for (auto [i, j] : moves) {
if (i <= on && j <= on) {
res.pb(tmp.back());
tmp.pop_back();
} else if (i > on && j > on) {
res.pb(i < j);
} else if (i > on) {
res.pb(0);
} else {
res.pb(1);
}
}
moves.clear();
return res;
}
void solve(int N, int V) {
on = n = N;
p = vi(n, 0);
iota(ALL(p), 1);
while (__builtin_popcount(n) > 1) {
n++;
p.pb(n);
}
REP (k, 0, MAXL) {
cerr << k << '\n';
for (int i = 1; (i << k) < n; i += 2) {
reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
}
RREP (l, k, 0) {
cerr << ' ' << l << '\n';
vii moves;
REP (i, 0, n) {
if (i >> l & 1) {
int j = i - (1 << l);
my_schedule(p[j], p[i]);
moves.pb({j, i});
}
}
vi res = my_visit();
assert(SZ(res) == SZ(moves));
REP (i, 0, SZ(res)) {
if (!res[i]) {
swap(p[moves[i].FI], p[moves[i].SE]);
}
}
for (int i : p) {
cerr << i << ' ';
}
cerr << '\n';
}
}
p.resize(on);
answer(p);
}
Compilation message (stderr)
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:82:61: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
82 | reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
| ~~^~~
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |