# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
317990 | Drew_ | Arranging Shoes (IOI19_shoes) | C++14 | 124 ms | 71696 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>
using namespace std;
int const N = 1e5 + 7;
int bit[2*N] = {};
void add(int x, int val)
{
x++;
while (x < 2*N)
bit[x] += val, x += (x & -x);
}
int sum(int x)
{
x++;
int res = 0;
while (x)
res += bit[x], x -= (x & -x);
return res;
}
queue<int> q[N];
bool type[N]; //false: left, true: right
long long count_swaps(std::vector<int> s)
{
long long res = 0;
for (int i = 0; i < s.size(); ++i)
{
if (q[abs(s[i])].empty() || !type[abs(s[i])] && s[i] < 0 || type[abs(s[i])] && s[i] > 0)
{
q[abs(s[i])].push(i);
if (s[i] < 0) type[abs(s[i])] = false;
else type[abs(s[i])] = true;
}
else
{
int target = q[abs(s[i])].front();
q[abs(s[i])].pop();
//cout << i << " -> " << target << ", shifted: " << sum(target) << ", cost: " << i - target - sum(target) << '\n';
res += i - target - sum(target);
if (s[i] > 0) res--;
add(target, 1);
add(i, -1);
}
}
return res;
}
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... |