# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
850064 | Bach21 | Arranging Shoes (IOI19_shoes) | C++14 | 70 ms | 12832 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 <bits/stdc++.h>
#include "shoes.h"
using namespace std;
const int nmax=2e5+5;
int BIT[nmax];
void update(int s,int val)
{
for (int i=s;i<nmax;i+=i&-i)
{
BIT[i]+=val;
}
}
int query(int s)
{
int res=0;
for (int i=s;i;i-=i&(-i))
{
res+=BIT[i];
}
return res;
}
long long count_swaps(vector<int> s)
{
long long res=0;
int n=(int)(s.size()/2);
vector<pair<int,int>> v[nmax];
for (int i=0;i<s.size();i++)
{
v[abs(s[i])].push_back({s[i],i});
}
vector<pair<int,int>> xl;
for (int i=1;i<=n;i++)
{
sort(v[i].begin(),v[i].end());
for (int j=0;j<(v[i].size()/2);j++)
{
int l=v[i][j].second;
int r=v[i][j+(int)(v[i].size()/2)].second;
if (l>r)
{
swap(l,r);
res++;
}
xl.push_back({l+1,r+1});
}
}
for (int i=1;i<=n*2;i++)
{
update(i,1);
}
sort(xl.begin(),xl.end());
for (auto x : xl)
{
res+=query(x.second-1)- query(x.first);
update(x.first,-1);
update(x.second,-1);
}
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... |