| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 346598 | Pety | 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 <bits/stdc++.h>
#include "shoes.h"
using namespace std;
int count_swaps (vector<int>v) {
map<int, int>mp[2];
set<pair<int, int>> s;
int ans = 0;
for (int i = 0; i < v.size(); i++) {
int x = v[i];
auto it = s.lower_bound({-x, 0});
if ((*it).first == -x) {
if (x > 0)
ans += i - (*it).second - 1;
else
ans += i - (*it).second;
s.erase(it);
}
else
s.insert({x, i});
}
return ans;
}
