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 <iostream>
#include <cstdio>
#include <queue>
#define N 200005
using namespace std;
int sz, Z=1e5, tr[N];
long long ans;
queue<int> qu[N];
void upd(int p, int q){
for(int i=p; i<=sz; i += i&-i) tr[i] += q;
}
int qry(int p){
int re=0;
for(int i=p; i; i -= i&-i) re += tr[i];
return re;
}
long long count_swaps(vector<int> a) {
int i, j, t;
sz = a.size();
for(i=1; i<=sz; i++) {
t = a[i-1];
if(qu[Z-t].empty()) {
qu[Z+t].push(i);
upd(i, 1);
} else {
j = qu[Z-t].front(); qu[Z-t].pop();
ans += i-j;
if(a[i]>0) ans--;
ans -= qry(i) - qry(j);
upd(j, -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... |