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 ;
const int N = 2e5 + 5 ;
map <int , set <int>> l , r ;
bool f[N] ;
long long count_swaps(vector<int> s) {
int n = s.size() , ans = 0 ;
for ( int i = 0 ; i < n ; i ++ ){
if ( s[i] < 0 ) l[-s[i]].insert(i) ;
else r[s[i]].insert(i) ;
}
for ( int i = 0 ; i < n ; i ++ ){
if ( f[i] == 1 ) continue ;
if ( s[i] < 0 ){
int ind = *r[-s[i]].begin() ;
r[-s[i]].erase(r[-s[i]].begin()) ;
ans += ind-i-1 ;
f[ind] = 1 ;
}
else{
int ind = *l[s[i]].begin() ;
l[s[i]].erase(l[s[i]].begin()) ;
ans += ind-i ;
f[ind] = 1 ;
}
}
return ans ;
}
# | 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... |