# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
849120 | abcvuitunggio | Arranging Shoes (IOI19_shoes) | C++17 | 46 ms | 16476 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 <bits/stdc++.h>
using namespace std;
int a[200001],cnt=1;
long long res,f[200001];
vector <int> pos[200001];
long long count_swaps(vector <int> s){
for (int i=s.size()-1;i>=0;i--)
pos[s[i]+s.size()/2].push_back(i);
for (int i=0;i<s.size();i++)
if (!a[i]){
a[i]=cnt;
int j=pos[s.size()/2-s[i]].back();
a[j]=cnt+1;
if (s[i]>0)
swap(a[i],a[j]);
pos[s[i]+s.size()/2].pop_back();
pos[s.size()/2-s[i]].pop_back();
cnt+=2;
}
for (int i=s.size()-1;i>=0;i--){
for (int j=a[i];j;j-=j&(-j))
res+=f[j];
for (int j=a[i];j<=s.size();j+=j&(-j))
f[j]++;
}
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... |