# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
346612 | Pety | Arranging Shoes (IOI19_shoes) | C++14 | 133 ms | 8684 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 aib[200002], n;
void update (int x, int val) {
for (int i = x; i <= n; i += (i & -i))
aib[i] += val;
}
int query (int x) {
int sum = 0;
for (int i = x; i; i -= (i & -i))
sum += aib[i];
return sum;
}
int calc (int x) {
x++;
return x + query(x);
}
long long count_swaps (vector<int>v) {
set<pair<int, int>> s;
n = v.size();
long long ans = 0;
for (int i = 0; i < v.size(); i++) {
int x = v[i];
auto it = s.lower_bound({-x, 0});
if (it != s.end() && (*it).first == -x) {
if (x > 0)
ans += calc(i) - calc((*it).second) - 1;
else
ans += calc(i) - calc((*it).second);
s.erase(it);
update(i + 1, -1);
update((*it).second + 1, 1);
}
else
s.insert({x, i});
}
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... |