# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640190 | ymm | Arranging Shoes (IOI19_shoes) | C++17 | 219 ms | 273652 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 <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
static const int N = 200'010;
static queue<int> l[N], r[N];
static int fen[N];
static void add_fen(int r, int x)
{
while (r > 0) {
fen[r] += x;
r -= r & -r;
}
}
static void add(int l, int r)
{
add_fen(r, 1);
add_fen(l, -1);
}
static int get(int i)
{
++i;
int ans = 0;
while (i < N) {
ans += fen[i];
i += i & -i;
}
return ans;
}
long long count_swaps(std::vector<int> s) {
ll ans = 0;
Loop (i, 0, s.size()) {
int x = s[i];
if (x < 0) {
if (r[-x].size()) {
ans += i - r[-x].front() - get(r[-x].front());
add(r[-x].front(), i);
r[-x].pop();
} else {
l[-x].push(i);
}
} else {
if (l[x].size()) {
ans += i - l[x].front() - get(l[x].front()) - 1;
add(l[x].front(), i);
l[x].pop();
} else {
r[x].push(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... |