# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
249170 | Dilshod_Imomov | 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 int long long
using namespace std;
int count_swaps( vector < int > s ) {
int n = (int)s.size(), ans = 0, sz = 0;
vector < int > ids, used(n);
map < int, vector < int > > vc;
for ( int i = 0; i < n; i++ ) {
vc[s[i]].push_back( i );
}
// cout << "Done 1" << endl;
for ( int i = 0; i < n; i++ ) {
if ( used[i] ) {
continue;
}
int l = i, r = *vc[-s[i]].begin();
// cout << "Done 2 " << l << ' ' << r << '\n';
vc[ s[i] ].erase( vc[ s[i] ].begin() );
int rr = r;
used[r] = 1;
vc[-s[i]].erase( vc[-s[i]].begin() );
int x = upper_bound( ids.begin(), ids.end(), i ) - ids.begin();
x = sz - x;
l += x;
x = upper_bound( ids.begin(), ids.end(), r ) - ids.begin();
x = sz - x;
r += x;
ans += r - l - 1;
if ( s[i] > 0 ) {
ans++;
}
sz++;
ids.push_back( rr );
}
return ans;
}
/*
int32_t main() {
int n;
cin >> n;
vector < int > S(2 * n);
for ( int i = 0; i < 2 * n; i++ ) {
cin >> S[i];
}
// cout << count_swaps( S );
}*/