# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
526470 | Deepesson | Arranging Shoes (IOI19_shoes) | C++17 | 486 ms | 149700 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"
#define MAX 550000
#define LSB(A) (A&(-A))
int ft[MAX];
void add(int p,int k){
p+=3;
while(p<MAX){
ft[p]+=k;
p+=LSB(p);
}
}
int query(int p){
p+=3;
int ans=0;
while(p>0){
ans+=ft[p];
p-=LSB(p);
}
return ans;
}
int seg(int l,int r){
return query(r)-query(l-1);
}
long long num_inversoes(std::vector<int> x){
///for(auto&z:x)std::cout<<z<<" ";std::cout<<"\n";
long long ans=0;
for(int i=0;i!=x.size();++i){
ans+=seg(x[i]+1,MAX-3);
add(x[i],1);
}
return ans;
}
long long count_swaps(std::vector<int> s) {
std::vector<int> posicoes(s.size());
std::map<int,std::queue<int>> mapal,mapar;
for(int i=0;i!=s.size();++i){
if(s[i]>0){
mapar[s[i]].push(i);
}else mapal[abs(s[i])].push(i);
}
bool pegou[s.size()]={};
int cur=0;
for(int i=0;i!=s.size();++i){
if(pegou[i])continue;
if(s[i]>0){///Direito
int x;
for(;;){
int u = mapal[abs(s[i])].front();
mapal[abs(s[i])].pop();
if(!pegou[u]){
x=u;
break;
}
}
pegou[x]=true;
pegou[i]=true;
posicoes[x]=cur;
posicoes[i]=cur+1;
}else {///Esquerdo
int x;
for(;;){
int u = mapar[abs(s[i])].front();
mapar[abs(s[i])].pop();
if(!pegou[u]){
x=u;
break;
}
}
pegou[x]=true;
pegou[i]=true;
posicoes[x]=cur+1;
posicoes[i]=cur;
}
cur+=2;
}
return num_inversoes(posicoes);
}
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... |