# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031253 | Andrey | Sorting (IOI15_sorting) | C++14 | 170 ms | 22768 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;
vector<int> haha(200001);
vector<int> bruh(200001);
vector<pair<int,int>> wut(0);
int calc(int n) {
wut.clear();
for(int i = 0; i < n; i++) {
bruh[i] = -1;
}
int br = 0;
for(int i = 0; i < n; i++) {
if(bruh[i] == -1) {
br++;
int p = i;
vector<pair<int,int>> wow(0);
while(bruh[p] == -1) {
bruh[p] = 1;
wow.push_back({haha[p],haha[haha[p]]});
p = haha[p];
}
wow.pop_back();
for(int j = 0; j < wow.size(); j++) {
wut.push_back(wow[j]);
}
}
}
return n-br;
}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
int l = 0,r = n;
while(l < r) {
int mid = (l+r)/2;
for(int j = 0; j < n; j++) {
haha[j] = s[j];
}
for(int j = 0; j < mid; j++) {
swap(haha[x[j]],haha[y[j]]);
}
if(calc(n) <= mid) {
r = mid;
}
else {
l = mid+1;
}
}
for(int j = 0; j < n; j++) {
haha[j] = s[j];
}
for(int j = 0; j < l; j++) {
swap(haha[x[j]],haha[y[j]]);
}
calc(n);
vector<int> pos(n);
for(int i = 0; i < n; i++) {
haha[i] = s[i];
pos[haha[i]] = i;
}
for(int i = 0; i < l; i++) {
int a = x[i],b = y[i];
swap(pos[haha[a]],pos[haha[b]]);
swap(haha[a],haha[b]);
if(i >= wut.size()) {
p[i] = 0;
q[i] = 0;
}
else {
p[i] = pos[wut[i].first];
q[i] = pos[wut[i].second];
swap(haha[pos[wut[i].first]],haha[pos[wut[i].second]]);
swap(pos[wut[i].first],pos[wut[i].second]);
}
}
return l;
}
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... |