# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1073210 | andrei_iorgulescu | Arranging Shoes (IOI19_shoes) | C++14 | 38 ms | 17244 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"
#warning That's not FB, that's not FB
using namespace std;
using ll = long long;
ll n;
ll a[200005];
vector<int> p[100005], neg[100005];
int per[200005];
int aib[200005];
void update(int pos, int val)
{
for (int i = pos; i <= 2 * n; i += (i & -i))
aib[i] += val;
}
int query(int pos)
{
int rr = 0;
for (int i = pos; i > 0; i -= (i & -i))
rr += aib[i];
return rr;
}
ll count_swaps(vector<int> S)
{
n = S.size() / 2;
for (int i = 1; i <= 2 * n; i++)
a[i] = S[i - 1];
for (int i = 1; i <= 2 * n; i++)
{
if (a[i] > 0)
p[a[i]].push_back(i);
else
neg[-a[i]].push_back(i);
}
ll ans = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < p[i].size(); j++)
{
if (p[i][j] < neg[i][j])
ans++, swap(p[i][j], neg[i][j]);
per[neg[i][j]] = p[i][j];
}
}
for (int i = 1; i <= 2 * n; i++)
update(i, 1);
for (int i = 1; i <= 2 * n; i++)
{
if (per[i] == 0)
continue;
ans += query(per[i] - 1) - query(i);
update(per[i], -1);
}
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... |