# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398457 | iulia13 | Arranging Shoes (IOI19_shoes) | C++14 | 8 ms | 9708 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 <iostream>
#include <vector>
#include "shoes.h"
using namespace std;
const int nmax = 1e5 + 5;
#define ll long long
ll aib[nmax * 4];
int moved[nmax], n;
vector <int> a[nmax * 4];
int lsb(int x)
{
return x & (-x);
}
void upd(int x, int val)
{
for (x; x <= n; x += lsb(x))
aib[x] += val;
}
ll qry(int x)
{
int s = 0;
while (x)
{
s += aib[x];
x -= lsb(x);
}
return x;
}
ll count_swaps(vector<int> v)
{
ll i, ans = 0;
n = v.size();
for (i = n - 1; 0 <= i; i--)
a[v[i] + n].push_back(i);
for (i = 0; i < n; i++)
{
if (moved[i])
continue;
ll j = a[n - v[i]].back(), swaps = 0; ///i < j
if (v[i] > 0)
swaps = 1;
///aduci j langa i adica pe i + 1
swaps += j - i - 1 - (qry(j) - qry(i));
upd(j, 1);
ans += swaps;
moved[j] = 1;
a[n - v[i]].pop_back();
a[n + v[i]].pop_back();
}
return ans;
}/*
int main()
{
int N, i;
cin >> N;
vector <int> v;
v.resize(N);
for (i = 0; i < N; i++)
cin >> v[i];
cout << count_swaps(v);
return 0;
}*/
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... |