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<queue<int>> r(n+1, queue<int>());
long long ans = 0;
int cnt = 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]].front() - cnt;
++cnt;
r[s[i]].pop();
} 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(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... |