# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
227950 | staniewzki | Arranging Shoes (IOI19_shoes) | C++17 | 170 ms | 14840 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>
using namespace std;
#include "shoes.h"
struct Fenwick {
vector<int> tree;
Fenwick(int n) : tree(n + 1) {}
void update(int pos, int val) {
for(pos++; pos < size(tree); pos += (pos & -pos))
tree[pos] += val;
}
int query(int pos) {
int ret = 0;
for(pos++; pos > 0; pos -= (pos & -pos))
ret += tree[pos];
return ret;
}
int query(int l, int r) {
return query(r) - query(l - 1);
}
};
long long count_swaps(vector<int> s) {
int m = size(s), n = m / 2;
vector<vector<int>> pos(m + 1);
for(int i = m - 1; i >= 0; i--)
pos[n + s[i]].emplace_back(i);
long long ans = 0;
Fenwick tree(m);
for(int i = 0; i < m; i++) {
if(!tree.query(i, i)) {
int j = pos[n - s[i]].back();
ans += j - (i + 1) - tree.query(i, j) + (s[i] > 0);
tree.update(j, +1);
pos[n - s[i]].pop_back();
pos[n + s[i]].pop_back();
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |