# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
599219 | Summers | Arranging Shoes (IOI19_shoes) | C++14 | 89 ms | 34664 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<vector>
using namespace std;
vector<long long>v[1000000];
long long fen[1000000];
void update(long long pos,long long val)
{
for(int i=pos;i<=1000000;i+=(i&-i))
{
fen[i]+=val;
}
}
long long sum(long long val)
{
long long ss=0;
for(int i=val;i>0;i-=(i&-i))
{
ss+=fen[i];
}
return ss;
}
bool is[1000000];
long long count_swaps(std::vector<int> s) {
long long i,j,n,res=0;
n=s.size()/2;
for(i=s.size()-1;i>=0;i--)
{
v[s[i]+n].push_back(i);
update(i+1,1);
}
for(i=0;i<s.size();i++)
{
if(is[i])continue;
is[i]=1;
v[s[i]+n].pop_back();
long long pos=v[-s[i]+n][v[-s[i]+n].size()-1];
v[-s[i]+n].pop_back();
is[pos]=1;
res+=sum(pos)-sum(i+1);
update(pos+1,-1);
if(s[i]>0)res++;
}
return res;
}
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... |