# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384220 | meperdonas203 | Arranging Shoes (IOI19_shoes) | C++17 | 502 ms | 147704 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;
void mapear(vector<int> &s){
int contador=0;
map<int,queue<int> > mapa;
for(auto &x:s){
if(!mapa[-x].empty()){
int indice=x;
x=-mapa[-x].front();
mapa[-indice].pop();
}else{
int valor=(x>0)?++contador:-1*(++contador);
mapa[x].push(valor);
x=valor;
}
}
}
long long int bit[100002];
long long int query(int indice){
int suma=0;
while(indice>0){
suma+=bit[indice];
indice-=(indice&(-indice));
}
return suma;
}
long long int query_2(int l,int r){
return(query(r)-query(l-1));
}
void update(int i,int valor,int n){
while(i<=n){
bit[i]+=valor;
i+=(i&(-i));
}
}
long long count_swaps(vector<int> s) {
long long int movs=0;
mapear(s);
int n=s.size()+1;
for(int i=0;i<s.size();i++){
if(s[i]>0 and query_2(abs(s[i]),abs(s[i]))==0){
movs++;
}
movs+=query_2(abs(s[i])+1,n);
update(abs(s[i]),1,n);
}
return movs;
}
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... |