#include "sorting.hpp"
#include <iostream>
#define s second
#define f first
#define pii pair<int,int>
using namespace std;
int idx[200005],a[200005];
pii d[200005];
int findSwapPairs(int N, int S[], int M, int x[], int y[], int p[], int q[]) {
bool c = 1;
for (int i=0;i<N;i++)
if (S[i] != i) c=0;
if (c) return 0;
int l = 1,r = M,ans = 0;
while(l <= r){
int mid = (l+r)>>1;
for (int i=0;i<N;i++){
a[i] = S[i];
idx[S[i]] = i;
}
for (int i = 0; i < mid; i++){
swap(a[x[i]],a[y[i]]);
swap(idx[a[x[i]]],idx[a[y[i]]]);
}
int cnt = 0;
for (int i = 0; i < N; i++){
if (a[i] == i) continue;
cnt++;
d[cnt] = {a[i],i};
int ind = idx[i];
swap(idx[a[i]],idx[i]);
swap(a[i],a[ind]);
}
if (cnt <= mid){
ans = mid;
for (int i=0;i<N;i++){
a[i] = S[i];
idx[S[i]] = i;
}
for (int i = 0; i < mid; i++){
swap(a[x[i]],a[y[i]]);
swap(idx[a[x[i]]],idx[a[y[i]]]);
p[i] = d[i].f; q[i] = d[i].s;
swap(idx[p[i]],idx[q[i]]);
p[i] = idx[p[i]]; q[i] = idx[q[i]];
swap(a[p[i]],a[q[i]]);
}
r = mid - 1;
}
else {
l = mid + 1;
}
}
return ans;
}
Compilation message
sorting.cpp:1:10: fatal error: sorting.hpp: No such file or directory
1 | #include "sorting.hpp"
| ^~~~~~~~~~~~~
compilation terminated.