# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143876 | RezwanArefin01 | Arranging Shoes (IOI19_shoes) | C++14 | 353 ms | 273312 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;
const int N = 2e5 + 10;
deque<int> pos[2][N];
int r[N], bit[N];
void update(int x) { ++x;
for(; x > 0; x -= x & -x)
++bit[x];
}
int read(int x) { ++x;
int ret = 0;
for(; x < N; x += x & -x)
ret += bit[x];
return ret;
}
long long count_swaps(vector<int> s) {
vector<int> ord;
for(int i = 0; i < s.size(); ++i) {
int x = abs(s[i]), c = s[i] > 0;
if(pos[c ^ 1][x].size()) {
int j = pos[c ^ 1][x].front();
pos[c ^ 1][x].pop_front();
r[j] = i;
} else {
pos[c][x].push_back(i);
ord.push_back(i);
}
}
long long ans = 0;
for(int i : ord) {
int L = i + read(i);
int R = r[i] + read(r[i]);
ans += R - L - 1;
if(s[i] > 0) ++ans;
update(R);
}
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... |