# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599258 | daisy2 | Arranging Shoes (IOI19_shoes) | C++14 | 57 ms | 15596 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;
vector<int> v[300005];
const int ma=100005;
int fenwick[300005];
void update(int p,int v)
{
for(int i=p;i<=100001;i+= i & -i)
{
fenwick[i]+=v;
}
}
long long sum(long long x)
{
long long r=0;
for(int i=x;i>0;i -= i & -i)
{
r+=fenwick[i];
}
return r;
}
bool used[300005];
long long count_swaps(std::vector<int> s) {
for(int i=s.size()-1;i>=0;i--)
{
if(v[ma+s[i]].empty()) v[ma+s[i]].push_back(0);
v[ma+s[i]].push_back(i);
v[ma+s[i]][0]++;
update(i+1,1);
}
int in2;
long long a=0;
for(int i=0;i<s.size();i++)
{
if(used[i]) continue;
in2=v[ma-s[i]][v[ma-s[i]][0]];v[ma-s[i]][0]--;
v[ma+s[i]][0]--;
used[in2]=1;
a+=sum(in2)-sum(i+1);
update(in2+1,-1);
if(s[in2]<s[i]) a++;
}
return a;
}
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... |