# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1218865 | vidux | 정렬하기 (IOI15_sorting) | C++17 | 0 ms | 0 KiB |
#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 = [&]() -> ll {
vi pos(n);
vi b(n);
ll cnt = 0;
for (int i = 0; i < n; i++) pos[a[i]] = i, b[i] = a[i];
for (int i = 0; i < n; i++) {
if (pos[i] != i) {
int p = pos[i];
swap(b[i], b[p]);
swap(pos[i], pos[b[p]]);
P[cnt] = i;
Q[cnt] = p;
cnt++;
}
}
return cnt;
};
int ans = opCnt();
//cout << ans << endl;
//for (int i = 0; i < ans; i++) cout << P[i] << " " << Q[i] << endl;
if (Y[0] == 1 && ans%2) p[ans] = 0, q[ans++] = 1;
return ans;
}