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;
int a[200001],cnt=1,n;
long long res,f[200001];
vector <int> pos[200001];
long long count_swaps(vector <int> s){
n=s.size()/2;
for (int i=n*2-1;i>=0;i--)
pos[s[i]+n].push_back(i);
for (int i=0;i<n*2;i++)
if (!a[i]){
a[i]=cnt;
int j=pos[n-s[i]].back();
a[j]=cnt+1;
if (s[i]>0)
swap(a[i],a[j]);
pos[s[i]+n].pop_back();
pos[n-s[i]].pop_back();
cnt+=2;
}
for (int i=n*2-1;i>=0;i--){
for (int j=a[i];j;j-=j&(-j))
res+=f[j];
for (int j=a[i];j<=n*2;j+=j&(-j))
f[j]++;
}
return res;
}
# | 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... |