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>
long long count_swaps(std::vector<int> s) {
int N = s.size() / 2;
std::map<int, std::set<int>> mp;
for(int i = 0; i < N * 2; i++)
{
mp[s[i]].insert(i);
}
long long ans = 0;
for(int i = 0; i < N * 2; i++)
{
if(mp[s[i]].empty())continue;
auto it = mp[-s[i]].upper_bound(i);
int ind = *it;
if(s[i] < 0)ans += ind - i - 1;
else ans += ind - i + 1;
mp[-s[i]].erase(it);
}
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... |