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>
using namespace std;
#define ll long long
queue<pair<int,int>> pos[200004];
ll count_swaps(vector<int> S){
ll n=S.size(),open=0,odp=0;
for (int i = 0; i<n; i++){
if (S[i]>0){
if (pos[S[i]+100000].empty()){
pos[S[i]].push({i,open});
open++;
}
else{
odp+=i-pos[S[i]+100000].front().first-1;
open--;
odp-=open-pos[S[i]+100000].front().second;
pos[S[i]+100000].pop();
}
}
else{
if (pos[-S[i]].empty()){
pos[100000-S[i]].push({i,open});
open++;
}
else{
odp+=i-pos[-S[i]].front().first;
open--;
odp-=open-pos[-S[i]].front().second;
pos[-S[i]].pop();
}
}
}
return odp;
}
# | 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... |