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;
long long count_swaps(vector<int> S) {
int n = S.size();
vector<queue<long long>> a(n);
vector<long long> pa(n);
long long tot = 0;
long long att = 0;
for (long long i = 0; i < n; i++) {
if (S[i] < 0) {
pa[i] = att;
a[-S[i]].push(att);
att += 2;
}
}
for (long long i = 0; i < n; i++) {
if (S[i] > 0) {
pa[i] = a[S[i]].front()+1;
a[S[i]].pop();
}
}
for (long long i = 0; i < n; i++) {
for (long long j = i+1; j < n; j++) {
if (pa[i] > pa[j]) tot++;
}
}
return tot;
}
# | 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... |