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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
int low = -1;
int high = m + 1;
while (high - low > 1) {
int mid = (high + low) >> 1;
vector<int> t(n);
for (int i = 0; i < n; i++) {
t[i] = s[i];
}
for (int i = 0; i < mid; i++) {
swap(t[x[i]], t[y[i]]);
}
vector<pair<int, int>> a;
vector<int> pos(n);
for (int i = 0; i < n; i++) {
pos[t[i]] = i;
}
for (int i = 0; i < n; i++) {
if (t[i] == i) {
continue;
}
int j = pos[i];
a.emplace_back(i, j);
swap(t[i], t[j]);
swap(pos[t[i]], pos[t[j]]);
}
if ((int) a.size() <= mid) {
for (int i = 0; i < mid; i++) {
if (i >= (int) a.size()) {
p[i] = q[i] = 0;
} else {
p[i] = a[i].first;
q[i] = a[i].second;
}
}
high = mid;
} else {
low = mid;
}
}
return high;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}
#endif
# | 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... |