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;
const long long maxn = 1e5+5;
long long N;
struct row {
vector<int> ar;
long long ch, ech;
friend void swap(row &a, row &b) {
a.ar.swap(b.ar);
swap(a.ch, b.ch);
swap(a.ech, b.ech);
}
};
row x,y;
void init(int n, vector<int> p) {
N = n;
x.ar = vector<int>(N);
y.ar = vector<int>(N);
for(int i = 0; i < N; i++) {
x.ar[i] = p[i]; // x to y
y.ar[p[i]] = i; // y to x
}
}
int fix(long long c) {
c += maxn * N;
return c % N;
}
void move_right(int K) {
x.ch += K;
}
void move_left(int K) {
x.ch -= K;
}
void swap_places() {
x.ech += ((x.ech + x.ch) % 2) ? -1 : 1;
}
void move_around() {
swap(x,y);
}
int get_position(int D) {
/*
Careful!
x[i] represents p[i+s mod N]
x[i-s mod N] represents p[i], the intended value
same for y
*/
long long ce = fix(D - y.ch - y.ech);
long long co = fix(D - y.ch + y.ech);
long long yp = -1;
if(ce % 2 == 0) {
yp = ce;
} else {
yp = co;
}
return fix(y.ar[yp] + x.ch + ((y.ar[yp] % 2) ? -x.ech : x.ech));
}
# | 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... |