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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll count_swaps(vector<int> T) {
ll n = T.size(), ans = 0LL;
vector<ll> S(n);
for(int i = 0; i < n; i++) S[i] = T[i];
unordered_map<ll,vector<ll>> M;
for(ll i = 0; i < n; i++) {
if(M[S[i]].size()) {
ans += (ll)i-M[S[i]].back();
if(S[i]>0LL) ans -= 1LL;
M[S[i]].pop_back();
}
else {
M[-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... |