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>
#define ll long long
using namespace std;
ll fen[200005];
int n;
void update(int id, int val) {
id++;
while(id <= n + 1) {
fen[id] += val;
id += (id & (-id));
}
return;
}
ll pre(int id) {
if(id <= -1) return 0;
int ans = 0;
id++;
while(id) {
ans += fen[id];
id -= (id & (-id));
}
return ans;
}
int range(int l, int r){
return pre(r) - pre(l - 1);
}
long long count_swaps(vector<int> arr) {
n = arr.size();
queue<int> pl[n + 5];
int dk[n + 5];
int t = 0;
for(int i = 0; i < n; i++) {
if(arr[i] < 0) {
dk[i] = t;
t++;
pl[-arr[i]].push(t);
t++;
}
}
for(int i = 0; i < n; i++) {
if(arr[i] > 0) {
dk[i] = pl[arr[i]].front();
pl[arr[i]].pop();
}
}
ll ans = 0;
for(int i = 0; i < n; i++) {
ans += i - pre(dk[i]);
update(dk[i], 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... |