# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
262030 | tiberiu | Arranging Shoes (IOI19_shoes) | C++14 | 89 ms | 16504 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 "shoes.h"
#include <vector>
using namespace std;
const int MAX_N = 2e5 + 10;
long long aib[MAX_N];
void update(int pos, int val) {
pos++;
while (pos < MAX_N) {
aib[pos] += val;
pos += (pos & -pos);
}
}
long long query(int pos) {
pos++;
long long ans = 0;
while (pos > 0) {
ans += aib[pos];
pos -= (pos & -pos);
}
return ans;
}
long long count_swaps(std::vector<int> s) {
int n = s.size() / 2;
vector<int>* f = new vector<int>[2 * n + 1]() + n;
if (query(2 * n))
return 1 / 0;
for (int i = 0; i < 2 * n; i++)
f[s[i]].push_back(i);
vector<int> p(2 * n);
for (int i = 1; i <= n; i++) {
int j = 0;
while (j < f[i].size()) {
p[f[i][j]] = f[-i][j];
p[f[-i][j]] = f[i][j];
j++;
}
}
long long ans = 0;
for (int i = 0; i < 2 * n; i++) {
if (p[i] < i)
continue;
if (s[p[i]] < s[i])
ans++;
ans += (p[i] - i - 1) - (query(p[i] - 1) - query(i));
update(p[i], +1);
}
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... |