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>
#include "sorting.h"
using namespace std;
int n,a[10000],b[10000];
int findSwapPairs(int N1, int S1[], int m, int X[], int Y[], int P[], int Q[]) {
n = N1;
for (int i = 0; i <n ;i++) {
a[i] = S1[i];
}
for (int i = 0; i < m ;i++) {
swap(a[X[i]],a[Y[i]]);
}
for (int i = 0; i < n; i++) {
b[a[i]] = i;
}
vector<pair<int,int> > ans;
for (int i = 0; i < n; i++) {
int j = i;
while (j && a[j] < a[j-1]) {
swap(a[j],a[j-1]);
ans.push_back({a[j],a[j-1]});
j--;
}
}
for (int i = 0; i < n; i++) {
b[S1[i]] = i;
}
for (int i = 0; i < m; i++) ans.push_back({0,0});
for (int i = 0; i < m; i++) {
swap(S1[X[i]],S1[Y[i]]);
b[S1[X[i]]] = X[i];
b[S1[Y[i]]] = Y[i];
swap(S1 [ b[ans[i].first]], S1[ b[ans[i].second ] ]);
P[i] = b[ans[i].first];
Q[i] = b[ans[i].second];
swap(b[ans[i].first], b[ans[i].second]);
}
return m;
} /*
main(){
int n,m;
cin >> n >> m;
int s1[n],p[n],q[n],x[m],y[m];
for (int i = 0; i < n;i++) cin >> s1[i];
for (int i = 0; i < m;i++) cin >> x[i] >> y[i];
int e = findSwapPairs(n,s1,m,x,y,p,q);
for (int i = 0; i < e; i++)
cout << p[i] <<' '<<q[i]<<endl;
} */
/* 5 6 4 3 2 1 0
0 1
1 2
2 3
3 4
0 1
1 2
*/
# | 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... |