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 <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#include "shoes.h"
ll count_swaps(vector<int> s) {
map<int, vector<int>> open, close;
vector<pair<int, int>> pairs;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] < 0) {
open[abs(s[i])].push_back(i);
} else {
close[abs(s[i])].push_back(i);
}
}
for (auto xop : open) {
const vector<int> &op = xop.y;
const vector<int> &cl = close[xop.x];
assert(op.size() == cl.size());
for (int i = 0; i < (int)op.size(); ++i) {
pairs.emplace_back(op[i], cl[i]);
}
}
ll answer = 0;
for (auto &e : pairs) {
if (e.x > e.y) {
++answer;
swap(e.x, e.y);
}
// cout << "# " << e.x << " " << e.y << endl;
}
for (int i = 0; i < (int)pairs.size(); ++i) {
for (int j = i + 1; j < (int)pairs.size(); ++j) {
int a = pairs[i].x, b = pairs[i].y, c = pairs[j].x, d = pairs[j].y;
if (a > c) {
swap(a, c), swap(b, d);
}
assert(a < c);
assert(a < b && c < d);
if (a < b && b < c && c < d) {
answer += 0;
} else if (a < c && c < b && b < d) {
answer += 1;
} else if (a < c && c < d && d < b) {
answer += 2;
} else {
assert(false);
}
}
}
return answer;
}
#ifdef LC
#include "grader.cpp"
#endif
# | 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... |