# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
223085 | emil_physmath | Sorting (IOI15_sorting) | C++17 | 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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include "sorting.h"
using namespace std;
int s[1000000];
static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE *_inputFile, *_outputFile;
static inline int _readInt() {
int res;
cin >> res;
return res;
}
int main()
{
int N, M;
N = _readInt();
int *S = (int*)malloc(sizeof(int) * (unsigned int)N);
for (int i = 0; i < N; ++i)
S[i] = _readInt();
M = _readInt();
int *X = (int*)malloc(sizeof(int) * (unsigned int)M), *Y = (int*)malloc(sizeof(int) * (unsigned int)M);
for (int i = 0; i < M; ++i) {
X[i] = _readInt();
Y[i] = _readInt();
}
int *P = (int*)malloc(sizeof(int) * (unsigned int)M), *Q = (int*)malloc(sizeof(int) * (unsigned int)M);
for (int i = 0; i < N; ++i)
s[i] = S[i];
int ans = findSwapPairs(N, s, M, X, Y, P, Q);
printf("%d\n", ans);
for (int i = 0; i < ans; ++i)
printf("%d %d\n", P[i], Q[i]);
for (int i = 0; i < ans; ++i)
{
swap(S[X[i]], S[Y[i]]);
swap(S[P[i]], S[Q[i]]);
}
for (int i = 0; i < N; ++i)
cout << S[i] << ' ';
}