# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1125259 | codexistent | Sorting (IOI15_sorting) | C++20 | 0 ms | 0 KiB |
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200005
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
ll p*, x*, s*, q*, r*;
vector<pair<ll, ll>> r;
ll st[MAXN], ed[MAXN];
bool v[MAXN];
vector<pair<ll, ll>> valid(ll m){
FOR(i, 0, n - 1) st[i] = i, v[i] = false;
FOR(i, 0, m - 1) swap(st[x[i]], st[y[i]]);
FOR(i, 0, n - 1) ed[st[i]] = i;
FOR(sti, 0, n - 1) if(!v[sti]) {
ll i = sti;
do{
}while(i != sti);
}
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
FOR(i, 0, n - 1) on[i] = S[i];
FOR(i, 0, M - 1) x[i] = X[i], y[i] = Y[i];
ll lo = 0, hi = M;
while(lo < hi){
ll md = (lo + hi) / 2;
r = valid(md);
if(r.size() <= md){
hi = md;
}else{
lo = md + 1;
}
}
FOR(i, 0, r.size() - 1) P[i] = r[i].first, Q[i] = r[i].second;
return lo;
}