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;
long long count_swaps(vector<int> s) {
int n = s.size();
vector<int> ft(n + 1);
auto up = [&](int i, int x) {
for (; i; i -= i & -i) {
ft[i] += x;
}
};
auto qry = [&](int i) {
int res = 0;
for (; i <= n; i += i & -i) {
res += ft[i];
}
return res;
};
map<int, deque<int>> dq;
long long res = 0;
for (int i = 0; i < n; ++i) {
if (dq.count(-s[i]) && dq[-s[i]].size()) {
int j = dq[-s[i]].front(); dq[-s[i]].pop_front();
up(j + 1, 1);
res += qry(j + 2) + (s[i] < 0);
} else {
dq[s[i]].push_back(i);
up(i + 1, 1);
}
}
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... |