# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
832687 | Marco_Escandon | Arranging Shoes (IOI19_shoes) | C++17 | 291 ms | 413420 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>
using namespace std;
typedef long long ll;
struct st{
vector<ll> asd;
void update(ll a, ll b)
{
for(a; a<asd.size(); a+=(a&(-a)))
{
asd[a]+=b;
}
}
ll query(ll a)
{
ll cont=0;
for(a; a>0; a-=(a&(-a)))
{
cont+=asd[a];
}
return cont;
}
st(ll n)
{
asd.resize(2*n);
}
};
#define op -s[i]+n
long long count_swaps(std::vector<int> s) {
ll n= s.size();
vector<ll> inv(n,0);
vector<queue<ll>> asd(n*3);
for(int i=0; i<n; i++)
asd[s[i]+n].push(i);
ll cont=1;
for(int i=0; i<n; i++)
{
if(s[i]!=0)
{
if(s[i]<0)
{
inv[i]=cont;
asd[s[i]+n].pop();
cont++;
inv[asd[op].front()]=cont;
cont++;
}
else
{
inv[i]=cont+1;
asd[s[i]+n].pop();
inv[asd[op].front()]=cont;
cont+=2;
}
s[asd[op].front()]=0;
asd[op].pop();
s[i]=0;
}
}
st asdf(n);
cont=0;
/*for(auto i:inv)
{
cout<<i<<" ";
}
cout<<"\n";*/
for(int i=n-1; i>-1; i--)
{
cont+=asdf.query(inv[i]);
asdf.update(inv[i],1);
}
return cont;
}
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... |