# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
376641 | beingsebi | Arranging Shoes (IOI19_shoes) | C++17 | 335 ms | 31224 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>
typedef long long ll;
using namespace std;
ll solve(vector<int> &ax)
{
vector<int> aib(ax.size() + 12);
auto qr = [&aib](int poz) {
ll rez = 0;
while (poz > 0)
rez += aib[poz], poz -= poz & -poz;
return rez;
};
auto upd = [&aib](int poz) {
while (poz < aib.size())
aib[poz]++, poz += poz & -poz;
};
ll rez = 0;
for (int i = 0; i < ax.size(); i++)
{
rez += qr(ax.size() + 2) - qr(ax[i] - 1);
upd(ax[i]);
}
return rez;
}
ll count_swaps(vector<int> v)
{
int n = (int)v.size();
unordered_map<int, int> mn, mp, dat;
unordered_map<int, vector<int>> mm;
vector<int> ax, rez;
ax.reserve(n);
for (size_t i = 0; i < v.size(); i++)
{
mm[v[i]].push_back(i);
if (v[i] > 0)
{
if (mn[v[i]] > mp[v[i]])
mn[v[i]]--;
else
{
mp[v[i]]++;
rez.push_back(v[i]);
}
}
else
{
v[i] = -v[i];
if (mp[v[i]] > mn[v[i]])
mp[v[i]]--;
else
{
mn[v[i]]++;
rez.push_back(v[i]);
}
v[i] = -v[i];
}
}
for (auto &i : mm)
reverse(i.second.begin(), i.second.end());
for (const auto &i : rez)
{
ax.push_back(mm[-i].back() + 1);
ax.push_back(mm[i].back() + 1);
mm[-i].pop_back();
mm[i].pop_back();
}
return solve(ax);
}
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... |