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 <queue>
#include "shoes.h"
using namespace std;
long long count_swaps(vector<int> s) {
long long n = s.size();
long long ans = 0;
queue<int> a[n / 2 + 1], b[n / 2 + 1];
for (int i = 0; i < n; i++) {
if (s[i] < 0) a[-s[i]].push(i);
else b[s[i]].push(i);
}
vector<int> c(n, 1);
for (int i = 0; i < n; i++) {
if (c[i] == 0) continue;
int ss = 0;
int x = s[i];
int j = i;
if (x < 0) {
int y = -x;
j = b[y].front();
b[y].pop();
a[y].pop();
} else {
j = a[x].front();
a[x].pop();
b[x].pop();
}
for (int jj = i + 1; jj < j; jj++) {
ss += c[jj];
}
c[j] = 0;
if (x > 0) ans++;
}
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... |