#include "shoes.h"
#include "bits/stdc++.h"
using namespace std;
long long count_swaps(vector<int> s) {
int n = s.size();
vector<bool> used(n, false);
map<int, queue<int>> pos;
for (int i = 0; i < n; ++i) {
pos[s[i]].push(i);
}
long long swaps = 0;
for (int i = 0; i < n; ++i) {
if (used[i]) continue;
int val = s[i];
int pair_pos = pos[-val].front(); pos[-val].pop();
used[i] = true;
used[pair_pos] = true;
int count_used = 0;
for (int j = i + 1; j < pair_pos; ++j) {
if (used[j]) count_used++;
}
swaps += pair_pos - i - 1 - count_used;
if (val > 0) swaps++;
}
return swaps;
}
# | 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... |