# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252172 | Hehehe | Sorting (IOI15_sorting) | C++14 | 0 ms | 0 KiB |
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> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#include "sorting.h"
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e9;
const ll mod = 1e9 + 9;
const int N = 2e5 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
int n = N, m = M;
for(int i = 0; i < n; i++){
pos[S[i]] = i;
}
vector<pi>ans;
for(int i = 0; i < n; i++){
if(S[i] == i)continue;
ans.push_back({i, pos[i]});
int x = S[i], y = S[pos[i]];
swap(S[i], S[pos[i]]);
pos[y] = i;
pos[x] = x;
}
int k = 0;
for(auto it : ans){
P[k] = it.ff;
Q[k] = it.ss;
k++;
}
return sz(ans);
}