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;
queue<int> posi[200002];
int n;
int fenwick[200002];
void update(int x, int k) {
while(x<=n*2) {
fenwick[x] += k;
x += (x & -x);
}
}
int query(int x) {
int ret = 0;
while(x>0) {
ret += fenwick[x];
x -= (x & -x);
}
return ret;
}
long long count_swaps(vector<int> S) {
n = S.size()/2;
long long ans = 0;
for(int i=0;i<2*n;i++) {
if(!posi[n-S[i]].empty()) {
ans += i-query(posi[n-S[i]].front())+(S[i]<0);
update(posi[n-S[i]].front(), 1);
posi[n-S[i]].pop();
} else {
posi[n+S[i]].push(i+1);
update(i+1, 1);
}
}
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... |