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;
#define ll long long
ll count_swaps(vector<int> S){
int N = S.size();
ll ans = 0;
map<int, ll> m;
map<int, deque<int>> id;
for(int i = 0; i < N; i++){
if(m[-S[i]] > 0){
if(S[i] < 0){
m[-S[i]]--;
ans += i - id[-S[i]].front();
id[-S[i]].pop_front();
}
else{
m[-S[i]]--;
ans += i - id[-S[i]].front() - 1;
id[-S[i]].pop_front();
}
}
else{
m[S[i]]++;
id[S[i]].push_back(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... |