# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
422719 | vanic | Sorting (IOI15_sorting) | C++14 | 1 ms | 332 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 "sorting.h"
#include <algorithm>
#include <iostream>
using namespace std;
const int maxn=2e5+5;
int pos[maxn];
int findSwapPairs(int n, int l[], int m, int x[], int y[], int p[], int q[]){
for(int i=0; i<n; i++){
pos[l[i]]=i;
}
int br=2;
int dr;
for(int i=0; i<n-2; i++){
swap(l[x[i]], l[y[i]]);
swap(pos[l[x[i]]], pos[l[y[i]]]);
p[i]=min(pos[br], br);
q[i]=max(pos[br], br);
dr=l[br];
swap(l[pos[dr]], l[pos[br]]);
swap(pos[br], pos[dr]);
br++;
}
int sol;
if(l[0]==0){
sol=n-2;
}
else{
sol=n-1;
swap(l[x[n-2]], l[y[n-2]]);
swap(pos[l[x[n-2]]], pos[l[y[n-2]]]);
p[n-2]=0;
if(l[0]!=0){
q[n-2]=1;
}
else{
q[n-2]=0;
}
}
/* cout << "krece" << endl;
for(int i=0; i<sol; i++){
cout << p[i] << ' ' << q[i] << '\n';
}*/
return sol-1;
}
/*
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int s[n];
for(int i=0; i<n; i++){
cin >> s[i];
}
int m;
cin >> m;
int x[m], y[m];
for(int i=0; i<m; i++){
cin >> x[i] >> y[i];
}
int p[m], q[m];
cout << findSwapPairs(n, s, m, x, y, p, q) << endl;
return 0;
}*/
Compilation message (stderr)
# | 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... |