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 MAXN 200010
long long nn;
long long niz[MAXN];
long long fenvik[MAXN];
map<long long,vector<long long>> mapa;
void update(long long x)
{
if (x<=2*nn)
{
fenvik[x]++;
x+=x&(-x);
}
}
long long sum(long long x)
{
long long ans=0;
while (x>0)
{
ans+=fenvik[x];
x-=x&(-x);
}
return ans;
}
long long count_swaps(std::vector<int> s)
{
nn=s.size()/2;
long long sol=0;
for (long long i=1;i<=2*nn;i++)
{
cout<<sol<<" ";
niz[i]=s[i-1];
if (mapa[-niz[i]].empty()) mapa[niz[i]].push_back(i);
else
{
long long poz=mapa[-niz[i]].back();
sol+=(i-poz-1-sum(i)+sum(poz-1));
mapa[-niz[i]].pop_back();
update(i);
update(poz);
}
cout<<sol<<endl;
}
return sol;
}
# | 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... |