# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
965386 | akacool445k | Arranging Shoes (IOI19_shoes) | C++14 | 1 ms | 504 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 <queue>
#include <iostream>
#include "shoes.h"
using namespace std;
int N;
int bit[200001];
int query(int i) {
int res = 0;
while (i > 0) {
res += bit[i];
i -= (i & -i);
}
return res;
}
void update(int i) {
while (i <= N) {
bit[i] = 0;
i += (i & -i);
}
}
long long count_swaps(vector<int> s) {
long long n = s.size();
long long ans = 0;
N = n;
queue<int> a[n / 2 + 1], b[n / 2 + 1];
for (int i = 0; i < n; i++) {
if (s[i] < 0) a[-s[i]].push(i);
else b[s[i]].push(i);
}
vector<int> c(n, 1);
for (int i = 0; i < n; i++) {
if (c[i] == 0) continue;
int ss = 0;
int x = s[i];
int j = i;
if (x < 0) {
int y = -x;
j = b[y].front();
b[y].pop();
a[y].pop();
} else {
j = a[x].front();
a[x].pop();
b[x].pop();
}
update(i + 1);
update(j + 1);
ans += query(j + 1);
c[j] = 0;
if (x > 0) ans++;
}
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... |