이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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"
const int N = 1 << 20;
int fen[N];
int f(int x) {
// cout << x << endl;
int s = 0;
for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
s += fen[i];
}
for (int i = x; i < N; i |= i + 1) {
++fen[i];
}
return s;
}
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;
}
sort(all(pairs));
reverse(all(pairs));
for (auto e : pairs) {
answer += f(e.y);
answer += f(e.x);
}
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... |