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>
typedef long long ll;
using namespace std;
long long int count_swaps(vector<int> s){
int n = s.size();
vector<set<int>> schuhe(n+1);
for(int i = 0;i<n;i++) {
if(s[i] > 0){
schuhe[s[i]].insert(i);
}
}
ll val = 0;
for(int i = 0;i<n;i++){
if(s[i] < 0){
int index = *schuhe[-s[i]].begin();
if(index == i+1){
schuhe[-s[i]].erase(index);
continue;
}
if(i > index){
val = val + abs(index-i);
}else{
val = val + index-i-1;
}
schuhe[-s[i]].erase(index);
}
}
return val;
}
# | 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... |