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 "choreography.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define BIT(x, i) ((x) >> (i) & 1)
#define MASK(i) (1LL << (i))
#define left ___left
#define right ___right
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i-- > 0; )
#define FOR(i, a, b) for (int _b = (b); i = (a); i < _b; ++i)
#define FORD(i, b, a) for (int _a = (a); i = (b); i-- > _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; }
template <class T> scan_op(vector <T>) { for (T &x: u) in >> x; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << "(" << u.fi << ", " << u.se << ")"; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple <U...>) { return print_tuple_utils<0, tuple <U...>> (out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream &>::type operator << (ostream &out, const Con &u) { out << "{"; for (auto it = u.begin(); it != u.end(); ++it) out << (it == u.begin() ? "" : ", ") << *it; return out << "}"; }
const int MAX = 1e5 + 5;
int N, A[2][MAX], sum[2], flip[2], cur;
void init(int _N, vector <int> P) {
N = _N;
REP(i, N) {
A[0][i] = P[i];
A[1][P[i]] = i;
}
}
void add(int &a, int b) {
a = (a + b) % N;
if (a < 0) a += N;
}
void move_right(int K) {
add(sum[cur], K);
if (K & 1) flip[cur] = -flip[cur];
}
void move_left(int K) {
add(sum[cur], -K);
if (K & 1) flip[cur] = -flip[cur];
}
void swap_places() {
flip[cur] = -flip[cur];
add(flip[cur], 1);
}
void move_around() {
cur ^= 1;
}
int get_position(int D) {
if (D & 1) add(D, -flip[cur ^ 1]);
else add(D, flip[cur ^ 1]);
add(D, -sum[cur ^ 1]);
int a = A[cur ^ 1][D];
add(a, sum[cur]);
add(a, flip[cur]);
if (!(a & 1)) add(a, -2 * flip[cur]);
return a;
}
# | 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... |