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>
#include <map>
#include <deque>
#include "shoes.h"
using namespace std;
long long count_swaps(vector<int> s){
int n=s.size();
map<int,deque<int>> np;
vector<int> a(n+1);
long long i,j,aux,rasp=0;
for(i=0;i<n;i++){
if(np[-s[i]].size()==0){
np[s[i]].push_back(i+1);
for (j=i+1;j<=n;j+=(i+1)&(-(i+1)))
a[j]++;
}else{
aux=np[-s[i]].front();np[-s[i]].pop_front();
rasp+=i;
for(j=aux;j;j-=aux&(-aux))
rasp-=a[j];
if(s[i]<0) rasp++;
for(j=aux;j<=n;j+=aux&(-aux))
a[j]++;
}
}
return rasp;
}
# | 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... |