# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
352363 | David_M | Arranging Shoes (IOI19_shoes) | C++14 | 180 ms | 14444 KiB |
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>
#define ll long long
using namespace std;
ll f[300005],b[300005],c[300005],o=1,N;
void upd(int x){for(;x<=2*N;x+=x&(-x))f[x]+=o;}
ll get(int x, ll Ans=0){for(;x;x-=x&(-x))Ans+=f[x];return Ans;}
long long count_swaps(vector<int> s){
ll x,ans=0;
map<ll, ll> a;
N=(int)s.size()/2;
vector<ll>ss(2*N);
for (int i=0; i<2*N; i++){
c[s[i]+2*N]++;
if(s[i]<0)ss[i]=-(c[s[i]+2*N]<<20)+s[i];
else ss[i]=(c[s[i]+2*N]<<20)+s[i];
}
for (int i=0; i<2*N; i++)a[abs(ss[i])]=i,upd(i+1); o=-1;
// for (int i=0; i<2*N; i++)cout<<s[i]<<" ";
for (int i=0; i<2*N; i++)if(!b[i+1])x=a[abs(ss[i])]+1,b[x]=1,ans+=get(x-1)-get(i)-(ss[i]<0),upd(x);
return ans;
}
Compilation message (stderr)
# | 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... |