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();
map<int, priority_queue<int>> m;
for(int i = 0; i < N; i++){
m[S[i]].push(-i);
}
ll ans = 0;
for(int i = 0; i < N; i++){
if(S[i] < 0){
ans += -m[S[i] + 2*S[i]].top() - i + 1;
}
else{
ans += -m[S[i] + 2*S[i]].top() - i;
}
}
return ans;
}
/*int main(){
cout << count_swaps({2, 1, -1, -2});
return 0;
}*/
# | 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... |