# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
669704 | victor_gao | Sorting (IOI15_sorting) | C++17 | 1 ms | 468 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 <bits/stdc++.h>
#define MAXN 200015
using namespace std;
int bk[MAXN],pos_bk[MAXN],pre[MAXN],pos_pre[MAXN];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
for (int i=0;i<N;i++){
bk[i]=i; pos_bk[i]=i;
pre[i]=S[i]; pos_pre[S[i]]=i;
}
for (int i=N-1;i>=0;i--){
swap(bk[X[i]],bk[Y[i]]);
pos_bk[bk[X[i]]]=X[i];
pos_bk[bk[Y[i]]]=Y[i];
}
for (int i=0;i<N;i++){
swap(pre[X[i]],pre[Y[i]]);
pos_pre[pre[X[i]]]=X[i];
pos_pre[pre[Y[i]]]=Y[i];
swap(bk[X[i]],bk[Y[i]]);
pos_bk[bk[X[i]]]=X[i];
pos_bk[bk[Y[i]]]=Y[i];
int now=i+1;
/*
cout<<"Now : ";
for (int j=0;j<N;j++)
cout<<pre[j]<<" \n"[j==N-1];
cout<<"pos_pre : ";
for (int j=0;j<N;j++)
cout<<pos_pre[j]<<" \n"[j==N-1];
cout<<"from back : ";
for (int j=0;j<N;j++)
cout<<bk[j]<<" \n"[j==N-1];
cout<<"from back pos : ";
for (int j=0;j<N;j++)
cout<<pos_bk[j]<<" \n"[j==N-1];
cout<<"swap "<<pos_pre[now]<<" "<<pos_bk[now]<<'\n';
*/
P[i]=pos_pre[now]; Q[i]=pos_bk[now];
swap(pre[pos_pre[now]],pre[pos_bk[now]]);
pos_pre[pre[pos_pre[now]]]=pos_pre[now];
pos_pre[pre[pos_bk[now]]]=pos_bk[now];
}
return N;
}
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... |