# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221773 | mathking1021 | Arranging Shoes (IOI19_shoes) | C++14 | 278 ms | 275708 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 <iostream>
#include <queue>
typedef long long ll;
using namespace std;
const ll M = 200000;
queue<ll> qu[400005];
ll d[200005];
ll n;
ll f(ll p)
{
ll re = 0;
p++;
while(p > 0)
{
re += d[p];
p -= (p & (-p));
}
return re;
}
void g(ll p)
{
p++;
while(p <= n)
{
d[p]--;
p += (p & (-p));
}
}
long long count_swaps(std::vector<int> s)
{
ll cnt = 0;
n = s.size();
for(ll i = 0; i < s.size(); i++)
{
qu[s[i] + M].push(i);
d[i + 1] = ((i + 1) & (-(i + 1)));
}
for(ll i = 0; i < s.size(); i++)
{
if(qu[M + s[i]].front() != i) continue;
ll j = qu[M - s[i]].front();
qu[M - s[i]].pop();
qu[M + s[i]].pop();
cnt += f(j) - f(i) - 1;
g(i), g(j);
if(s[i] > 0) 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... |