# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133669 | MAMBA | Sorting (IOI15_sorting) | C++17 | 598 ms | 14328 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>
using namespace std;
#define rep(i , j , k) for (int i = j; i < (int)k; i++)
const int MAXN = 2e5 + 10;
int p[MAXN], q[MAXN], arr[MAXN], rra[MAXN];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
auto check = [&](int lim) -> bool {
iota(p , p + N , 0);
iota(q , q + N , 0);
memcpy(arr , S , N * 4);
rep(i , 0 , N)
rra[arr[i]] = i;
for(int i = lim - 1; ~i; i--) {
if (X[i] == Y[i]) continue;
swap(p[X[i]] , p[Y[i]]);
swap(q[p[X[i]]] , q[p[Y[i]]]);
}
int ptr = 0, cnt = 0;
for(int i = 0; i < lim; i++) {
if (X[i] != Y[i]) {
swap(p[X[i]] , p[Y[i]]);
swap(q[p[X[i]]] , q[p[Y[i]]]);
swap(arr[X[i]] , arr[Y[i]]);
swap(rra[arr[X[i]]] , rra[arr[Y[i]]]);
}
while (ptr < N && arr[q[ptr]] == ptr) {
ptr++;
}
if (ptr < N) {
int pos = rra[ptr];
// as pos bayad bere be q[ptr]
int sop = q[ptr];
P[cnt] = pos;
Q[cnt++] = sop;
swap(arr[pos] , arr[sop]);
swap(rra[arr[pos]] , rra[arr[sop]]);
}
}
while (ptr < N && arr[q[ptr]] == ptr) {
ptr++;
}
while (cnt < N) {
P[cnt] = Q[cnt] = 0;
cnt++;
}
return ptr == N;
};
int l = -1 , r = N;
while (l != r - 1) {
int mid = l + r >> 1;
if (check(mid))
r = mid;
else
l = mid;
}
check(r);
return r;
}
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... |