#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const ll LLINF = 1e18;
int findSwapPairs(int N, int a[], int M, int X[], int Y[], int P[], int Q[]) {
int n = N;
int l = 0, r = M;
auto opCnt = [&]() -> int {
vi pos(n);
vi b(n);
int cnt = 0;
for (int i = 0; i < n; i++) pos[a[i]] = i, b[i] = a[i];
for (int i = n-1; i > 1; i--) {
if (pos[i] != i) {
if (Y[0] == 1) {
swap(pos[b[0]], pos[b[1]]);
swap(b[0], b[1]);
}
int p = pos[i];
swap(b[i], b[p]);
swap(pos[i], pos[b[p]]);
P[cnt] = i;
Q[cnt] = p;
cnt++;
}
}
if (b[0] != 0) {
P[cnt] = 0;
Q[cnt] = (Y[0] != 1);
cnt++;
}
return cnt;
};
int ans = opCnt();
//cout << ans << endl;
//for (int i = 0; i < ans; i++) cout << P[i] << " " << Q[i] << endl;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |