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>
#include "shoes.h"
using namespace std;
#define ll long long
const int MAXN = 1e5 + 10;
int bit[MAXN];
void upd(int i, int val){
for(i++; i <= MAXN; i += -i & i){
bit[i - 1] += val;
}
}
ll clc(int i){
ll res = 0;
for(i++; i > 0; i -= -i & i){
res += bit[i - 1];
}
return res;
}
ll clc(int l, int r){
return clc(r) - clc(l - 1);
}
long long count_swaps(vector<int> s) {
ll res = 0;
int n = s.size();
vector<vector<int>> vec(n + 1);
for(int i = n - 1; i >= 0; i--){
vec[s[i] + n / 2].push_back(i);
}
for(int i = 0; i < n; i++){
if(vec[s[i] + n / 2].back() != i) continue;
int x = vec[-s[i] + n / 2].back();
vec[s[i] + n / 2].pop_back();
vec[-s[i] + n / 2].pop_back();
res += x - i - (s[i] < 0) - clc(i, x);
upd(i, 1);
upd(x, 1);
}
return res;
}
# | 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... |