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;
using ll = long long;
#define all(x) begin(x), end(x)
long long count_swaps(std::vector<int> s) {
int n = s.size()/2;
vector<ll> fen(2*n+1);
auto add = [&](int x) {
for(; x <= 2*n; x += x&-x) fen[x]++;
};
auto get = [&](int x) {
int res = 0;
add(x);
for(; x; x -= x&-x)
res += fen[x];
return res;
};
ll res = 0;
map<int, int> tie;
for(auto &i : s) i = 2*abs(i) + (i>0);
vector<array<int, 3>> b;
for(int i = 0; i < 2*n; i++)
b.push_back({s[i], tie[s[i]]++, i+1});
sort(all(b), [&](auto x, auto y) {
if(x[0]/2 != y[0]/2) return x[0]/2 < y[0]/2;
if(x[1] != y[1]) return x[1] < y[1];
return x[0] < y[0];
});
int cur = 0;
for(auto [_, __, i] : b) {
//cout << _ << " " << __ << " " << i << endl;
res += ++cur - get(i);
}
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... |