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 = (int)s.size() / 2;
vector<vector<int>> l(n+1, vector<int>());
vector<vector<int>> r(n+1, vector<int>());
long long ans = 0;
for (int i = 0; i < (int)s.size(); ++i) {
if (s[i] < 0) {
s[i] = -s[i];
if (r[s[i]].size()) {
ans += i - r[s[i]].back();
r[s[i]].pop_back();
} else
l[s[i]].push_back(i);
} else {
if (l[s[i]].size()) {
ans += i - l[s[i]].back() - 1;
l[s[i]].pop_back();
} else
r[s[i]].push_back(i);
}
}
return ans;
}
# | 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... |