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 <bits/stdc++.h>
#include "shoes.h"
using namespace std;
const long long MX=2e5+5;
queue < long long > st[2*MX];
long long fen[2*MX],a[2*MX];
long long n;
void upd(long long in,long long zn)
{
while(in<=n)
{
fen[in]+=zn;
in|=(in+1);
}
}
long long fget(long long in)
{
long long rt=0;
while(in>0)
{
rt+=fen[in];
in=(in&(in+1))-1;
}
return rt;
}
long long count_swaps(vector<int> s)
{
n=s.size();
for(long long i=0;i<n;i++)
{
a[i+1]=s[i];
}
for(long long i=1;i<=n;i++)
{
upd(i,1);
}
long long ans=0;
for(long long i=1;i<=n;i++)
{
if(!st[MX-a[i]].empty())
{
long long l=st[MX-a[i]].front();
st[MX-a[i]].pop();
ans+=fget(i)-fget(l)-(a[i]>0);
upd(i,-1);
upd(l,1);
}
else
{
st[MX+a[i]].push(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... |