# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019466 | Nicolaikrob | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 KiB |
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<ll> S) {
ll n = S.size(), ans = 0LL;
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;
}