# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143777 | jwvg0425 | Arranging Shoes (IOI19_shoes) | C++17 | 119 ms | 20856 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 "shoes.h"
#include <set>
std::set<int> minus[100005];
std::set<int> plus[100005];
long long count_swaps(std::vector<int> s) {
std::vector<bool> used(s.size(), false);
long long ans = 0;
long long useCount = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] > 0)
plus[s[i]].insert(i);
else
minus[-s[i]].insert(i);
}
for (int i = 0; i < s.size(); i++)
{
if (used[i])
{
useCount--;
continue;
}
if (s[i] > 0)
{
int near = *minus[s[i]].lower_bound(i);
minus[s[i]].erase(near);
used[near] = true;
ans += near - i - useCount;
}
else
{
int near = *plus[-s[i]].lower_bound(i);
plus[-s[i]].erase(near);
used[near] = true;
ans += near - i - 1 - useCount;
}
useCount++;
}
return ans;
}
Compilation message (stderr)
# | 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... |