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 <iostream>
#include <vector>
using namespace std;
vector<int> lista[200001];
long long int temp[200001];
long long count_swaps(vector<int> v){
long long int total=0, z=v.size();
for(int i=1; i<200001; ++i){
for(int j=i; j<200001; j+=j&-j){
temp[j]++;
}
}
for(int i=0; i<z; ++i){
int a=v[i];
if(a<0){
if(!lista[-a+z].empty()){
long long int temp1=0, temp2=0;
for(int j=i+1; j>0; j-=j&-j){
temp1+=temp[j];
}
temp1+=temp[0];
for(int j=lista[-a+z].front()+1; j>0; j-=j&-j){
temp2+=temp[j];
}
temp2+=temp[0];
total+=temp1-temp2;
for(int j=lista[-a+z].front()+1; j<200001; j+=j&-j){
temp[j]++;
}
for(int j=i+1; j<200001; j+=j&-j){
temp[j]--;
}
lista[-a+z].erase(lista[-a+z].begin());
} else {
lista[a+z].push_back(i);
}
} else {
if(!lista[-a+z].empty()){
long long int temp1=0, temp2=0;
for(int j=i+1; j>0; j-=j&-j){
temp1+=temp[j];
}
temp1+=temp[0];
for(int j=lista[-a+z].front()+1; j>0; j-=j&-j){
temp2+=temp[j];
}
temp2+=temp[0];
total+=temp1-temp2;
total--;
for(int j=lista[-a+z].front()+1; j<200001; j+=j&-j){
temp[j]++;
}
for(int j=i+1; j<200001; j+=j&-j){
temp[j]--;
}
lista[-a+z].erase(lista[-a+z].begin());
} else {
lista[a+z].push_back(i);
}
}
}
return total;
}
# | 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... |