#include <bits/stdc++.h>
int findSwapPairs(int n, int a[], int m, int u[], int v[], int uu[], int vv[]) {
int l = 0, r = m, best = m;
int inv[200'005];
while (l <= r) {
int mid = (l + r) >> 1;
for (int i = 0; i <= mid; i++) {
std::swap(a[u[i]], a[v[i]]);
}
for (int i = 0; i < n; i++) {
inv[a[i]] = i;
}
int need = 0;
for (int i = 0; i < n; i++) {
if (a[i] == i) {
continue;
}
int node = i;
while (a[node] != node) {
std::swap(a[node], a[inv[node]]);
uu[need] = node;
vv[need] = inv[node];
need++;
node = inv[node];
int x = node;
int y = inv[node];
inv[a[x]] = x;
inv[a[y]] = y;
}
}
if (need <= mid) {
best = mid;
r = mid - 1;
} else {
l = mid + 1;
}
for (int i = 0; i <= mid; i++) {
std::swap(a[u[i]], a[v[i]]);
}
}
return best;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Incorrect |
1 ms |
980 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Incorrect |
1 ms |
1072 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1108 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |