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;
#define FOR(i,n) for (int i=0;i<(n);++i)
const int N=1e6+6;
priority_queue<int> mn[N],d;
int fw[N];
int n;
int get(int ind){
int ans=0;
for(;ind>=0;ind=(ind&(ind+1))-1){
ans+=fw[ind];
}
return ans;
}
void add(int ind,int val){
for(;ind<n;ind=ind|(ind+1)){
fw[ind]+=val;
}
}
long long count_swaps(vector<int> s) {
n=s.size();
FOR(i,n){
if (s[i]<0){
d.push(-i);
}
else{
mn[s[i]].push(i);
}
}
long long ans=0;
FOR(i,n/2){
int a=-d.top();
d.pop();
int b=mn[-s[a]].top();
mn[-s[a]].pop();
if (b<a)ans++;
ans+=a+b-4*i-1+get(a)+get(b);
add(a,-1);
add(b,-1);
add(0,2);
}
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... |