# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227695 | Romario8 | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 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<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define rl "\n"
#define x first
#define y second
using namespace std;
long long count_swaps(vector<ll> s)
{
ll ans=0;
ll n=s.size();
vector<vector<ll>> pr(2*n+1);
rep(i,0,n)
{
pr[s[i]+n].pb(i);
if(pr[-s[i]+n].size()!=0)
{
ans+=i-pr[-s[i]+n][0];
if(s[i]>0)ans--;
pr[-s[i]+n].erase(pr[-s[i]+n].begin());
pr[s[i]+n].erase(pr[s[i]+n].begin());
}
}
return ans;
}