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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
queue<int> pass[200005];
int tree[200005], MAXS;
long long ans;
void update(int u, int idx){
idx++;
for(int i = idx; i <= MAXS; i += i & -i){
tree[i] += u;
}
}
int getans(int idx){
idx++;
int res = 0;
for(int i = idx; i > 0; i -= i & -i)
res += tree[i];
return res;
}
long long count_swaps(vector<int> s) {
MAXS = s.size();
for(int R = 0; R < MAXS; R++){
if(!pass[100000-s[R]].empty()){
int L = pass[100000-s[R]].front();
// cout << R << " " << L << "\n";
pass[100000-s[R]].pop();
if(s[R] > 0){
ans += R - L - 1;
}else ans += R - L;
ans -= getans(R) - getans(L);
update(-1, L);
}else{
pass[100000 + s[R]].push(R);
update(1, R);
}
}
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... |