# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
590992 | almothana05 | Arranging Shoes (IOI19_shoes) | C++14 | 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 "shoes.h"
#include <bits/stdc++.h>
using namespace std;
map<long long , vector<long long> >num;
vector<pair<long long , long long> >erg;
long long vis[200000] , pref[200000];
long long count_swaps(vector<long long> s) {
long long menge = s.size() , be , en , re = 0;
for(long long i = menge - 1 ; i >= 0 ; i--){
num[s[i]].push_back(i);
}
for(long long i = 0 ; i < menge ; i++){
if(vis[i] == 1){
continue;
}
be = i;
en = num[s[i] * -1][num[s[i] * -1].size() - 1];
num[s[i] * -1].pop_back();
num[s[i]].pop_back();
if(be > en){
swap(be , en);
}
for(long long j = be ; j <= en ; j++){
pref[j]++;
}
vis[be] = 1;
vis[en] = 1;
be += pref[be];
en += pref[en];
if(s[i] > 0){
re++;
}
re += (en - be - 1);
}
return re;
}