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;
const int MAXN = 1e5 + 5;
typedef long long ll;
int n;
int inv(int x){
if(x<0) return -x;
else if(x>n) return x - n;
else return x + n;
}
ll count_swaps(vector<int> S){
ll ans1 = 0, ans2 = 0;
n = S.size() / 2;
queue<int> mp[2 * n + 2];
int nxt = 0;
for(int i=0; i<2*n; i++) {
if(mp[inv(S[i])].size()){
ans1 += abs(mp[inv(S[i])].front() - nxt) + abs(i - nxt - 1);
ans2 += (S[i]<0);
nxt += 2;
mp[inv(S[i])].pop();
}
else{
mp[inv(inv(S[i]))].push(i);
}
}
return ans1 / 2 + ans2;
}
# | 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... |