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;
typedef long long ll;
ll count_swaps(vector<int>s) {
int n = s.size();
map<int, int>p;
vector<int>a(n);
for(int i = 0, index = 1; i < n; i++){
auto it = p.find(-s[i]);
if(it != p.end()){
a[i] = it->second + (s[i] < 0 ? -1 : 1);
p.erase(it);
}
else{
p[s[i]] = a[i] = index + int(s[i] > 0);
index += 2;
}
}
vector<int>bit(n + 1, 0);
auto update = [&] (int p){
for(; p <= n; p += p & -p){
bit[p]++;
}
};
auto get = [&] (int p){
int ans = 0;
for(; p > 0; p -= p & -p){
ans += bit[p];
}
return ans;
};
ll ans = 0;
for(int i = 0; i < n; i++){
ans += i - get(a[i]);
update(a[i]);
}
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... |