#include <bits/stdc++.h>
//#include "sorting.h"
using namespace std;
#define ll long long
#define vb vector<bool>
#define pb push_back
#define ff(aa, bb, cc) for(int aa = bb; aa < cc; aa++)
#define vl vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define ed "\n"
#define all(aaa) aaa.begin(), aaa.end()
#define rall(aaa) aaa.rbegin(), aaa.rend()
ll MOD = 1e9+7;
int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]){
vector<int> pos(n);
bool caso = false;
if(Y[0] == 1){
caso = true;
}
ff(i, 0, n){
//cout << S[i] << " " << i << ed;
pos[S[i]] = i;
}
int c = 0;
vector<int> p, q;
/*ff(id, 0, n){
cout << pos[id] << " ";
}
cout << ed << ed;
ff(id, 0, n){
cout << S[id] << " ";
}
cout << ed << ed;*/
ff(i, 0, n){
if(pos[i] != i){
c++;
if(caso){
c++;
p.pb(0);
q.pb(0);
}
//cout << pos[i] << " " << i << ed;
//cout << S[pos[i]] << " " << S[i] << ed;
p.pb(S[pos[i]]);
q.pb(pos[i]);
swap(S[pos[i]], S[i]);
swap(pos[S[pos[i]]], pos[S[i]]);
}
/*ff(id, 0, n){
cout << S[id] << " ";
}
cout << ed << ed << ed;*/
}
ff(i, 0, p.size()){
P[i] = p[i];
Q[i] = q[i];
}
return c;
}
/*
int main()
{
int N, M;
cin >> N;
int S[N];
ff(i, 0, N){
cin >> S[i];
}
cin >> M;
int X[M], Y[M];
ff(i, 0, M){
cin >> X[i] >> Y[i];
}
int P[M], Q[M];
int x = findSwapPairs(N, S, M, X, Y, P, Q);
cout << x << ed;
ff(i, 0, M){
if(P[i] < 0 || P[i] >= N || Q[i] < 0 || Q[i] >= N){
return 0;
}
cout << P[i] << " " << Q[i] << ed;
}
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |