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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 20;
int order[maxN * 2];
int sizes[maxN * 2];
int match[maxN * 2];
bool flag[maxN * 2];
vector<int> shoes[maxN][2];
long long count_swaps(vector<int> _sizes) {
int n = (int)_sizes.size() / 2;
for (int i = 1; i <= n * 2; i++) {
sizes[i] = _sizes[i - 1];
if (sizes[i] < 0) {
shoes[-sizes[i]][0].push_back(i);
}
else {
shoes[sizes[i]][1].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < (int)shoes[i][0].size(); j++) {
match[shoes[i][0][j]] = shoes[i][1][j];
match[shoes[i][1][j]] = shoes[i][0][j];
}
}
int cnt = 0;
for (int i = 1; i <= n * 2; i++) {
if (!flag[i]) {
order[i] = cnt + (sizes[i] < 0 ? 1 : 2);
order[match[i]] = cnt + (sizes[match[i]] < 0 ? 1 : 2);
flag[i] = true;
flag[match[i]] = true;
cnt += 2;
}
}
int res = 0;
for (int i = 1; i <= n * 2; i++) {
for (int j = i + 1; j <= n * 2; j++) {
if (order[i] > order[j]) {
res++;
}
}
}
return res;
}
# | 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... |