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;
#include "shoes.h"
long long count_swaps(vector<int> s)
{
size_t const n = s.size();
vector<bool> processed(n, 0);
vector<priority_queue<unsigned, vector<unsigned>, greater<unsigned>>> q(n);
for (unsigned i = 0; i < n; i++)
q[2 * (abs(s[i]) - 1) + (s[i] < 0)].push(i);
long long swaps_needed = 0;
for (unsigned i = 0; i < n; i++)
{
if (!processed[i])
{
processed[i] = 1;
while (processed[q[2 * (abs(s[i]) - 1) + (s[i] > 0)].top()])
q[2 * (abs(s[i]) - 1) + (s[i] > 0)].pop();
unsigned j = q[2 * (abs(s[i]) - 1) + (s[i] > 0)].top();
q[2 * (abs(s[i]) - 1) + (s[i] > 0)].pop();
processed[j] = 1;
swaps_needed += j - i - (s[i] < 0);
}
}
return swaps_needed;
}
# | 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... |