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;
long long n,a[200069],pst[200069],c=0,z=0,fw[200069],fwp;
unordered_map<long long,long long> fq;
unordered_map<long long,queue<long long>> q;
long long count_swaps(vector<int> v)
{
long long i,k;
n=v.size();
for(i=1;i<=n;i++)
{
if(fq[-v[i-1]])
{
a[i]=q[-v[i-1]].front()*2;
q[-v[i-1]].pop();
fq[-v[i-1]]--;
}
else
{
c++;
a[i]=c*2;
q[v[i-1]].push(c);
fq[v[i-1]]++;
}
if(v[i-1]<0)
{
a[i]--;
}
}
for(i=1;i<=n;i++)
{
pst[a[i]]=i;
}
for(i=1;i<=n;i++)
{
k=0;
for(fwp=pst[i]-1;fwp>0;fwp-=fwp&-fwp)
{
k+=fw[fwp];
}
z+=pst[i]-1-k;
for(fwp=pst[i];fwp<=200000;fwp+=fwp&-fwp)
{
fw[fwp]++;
}
}
return z;
}
# | 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... |