# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
240870 | RayaBurong25_1 | Arranging Shoes (IOI19_shoes) | C++17 | 806 ms | 147128 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 <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
int abs(int a)
{
return (a < 0)?-a:a;
}
int ismoved[200005] = {0};
int query(int p)
{
p++;
int r = 0;
for (; p > 0; p -= p&-p)
r += ismoved[p];
return r;
}
void update(int p)
{
p++;
for (; p < 200005; p += p&-p)
ismoved[p]++;
}
long long count_swaps(std::vector<int> s) {
int i, sz, norp;
long long cnt = 0;
std::map<int, std::queue<int> > pos[2];
for (i = 0; i < s.size(); i++)
{
sz = abs(s[i]);
norp = (s[i] > 0);
if (pos[norp].find(sz) == pos[norp].end())
pos[norp][sz] = std::queue<int>();
pos[norp][sz].push(i);
}
std::vector<int> moved;
int nxt;
for (i = 0; i < s.size(); i++)
{
sz = abs(s[i]);
norp = (s[i] > 0);
if (i > 0 && query(i) - query(i-1))
continue;
// printf("%d ", sz);
if (pos[!norp][sz].size() == 0)
continue;
nxt = pos[!norp][sz].front();
// printf("%d ", pos[sz][nxt]);
cnt += (nxt - i - 1) - (query(nxt) - query(i));
// printf("%d ", (s[i] > 0));
cnt += (s[i] > 0);
update(nxt);
pos[!norp][sz].pop();
pos[norp][sz].pop();
// printf("%lld\n", cnt);
}
return cnt;
}
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... |