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"
using namespace std;
long long count_swaps(std::vector<int> s) {
int n = s.size()/2;
stack<int> negative[n+1];
stack<int> positive[n+1];
long long ans = 0;
for(int i=0; i<2*n; i++){
if(s[i]<0){
if(!positive[-1*s[i]].empty()){
ans+= i-positive[-1*s[i]].top();
positive[-1*s[i]].pop();
}
else{
negative[-1*s[i]].push(i);
}
}
else{
if(!negative[s[i]].empty()){
ans+= i-negative[s[i]].top()-1;
negative[s[i]].pop();
}
else{
positive[s[i]].push(i);
}
}
}
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... |