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;
typedef long long ll;
int N;
int S[200001],Idx[200001];
bool Used[200001];
queue<int> A[100001];
int my_abs(int x){
if (x<0)
return -x;
return x;
}
ll count_swaps(vector<int> s){
ll ans=0;
N=(int)s.size();
for (int i=1; i<=N; i++)
S[i]=s[i-1];
for (int i=1; i<=N; i++){
int x=my_abs(S[i]);
if (!A[x].empty()&&S[A[x].front()]+S[i]==0){
Idx[A[x].front()]=i;
A[x].pop();
}
else
A[x].push(i);
}
for (int i=1; i<=N; i++){
if (Used[i])
continue;
for (int j=i+1; j<Idx[i]; j++)
ans+=(!Used[j]);
if (S[i]>S[Idx[i]])
ans++;
Used[i]=Used[Idx[i]]=true;
}
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... |