# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143373 | ondrah | 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 <iostream>
using namespace std;
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <set>
#include <map>
using namespace std;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long count_swaps(std::vector<int> s) {
long long ans = 0;
int n = s.size();
ordered_set<int> els;
map<int, multiset<int>> M;
for(int i = 0; i < n; i++) {
els.insert(i);
M[s[i]].insert(i);
}
for(int i = 0; i < n; i++) {
if(s[i] == n+2)
continue;
int j = *M[-s[i]].begin();
M[-s[i]].erase(M[-s[i]].begin());
int pos1 = els.order_of_key(i);
int pos2 = els.order_of_key(j);
els.erase(els.find(j));
ans += pos2-pos1;
if(s[i] > 0) ans++;
break;
}
return ans;
}
int main() {
// your code goes here
return 0;
}