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+10;
deque<int> d[2*MAXN];
int sh[MAXN];
bitset<MAXN> v;
long long count_swaps(vector<int> s) {
int N=s.size();
for(int i=0;i<N;i++)d[s[i]+MAXN].push_back(i);
long long ans=0;
int cont=0;
for(int i=0;i<N;i++){
if(v[i])continue;
cont+=sh[i];
v[i]=1;
sh[i+1]++;
assert(d[s[i]+MAXN].front()==i);
d[s[i]+MAXN].pop_front();
int h=d[MAXN-s[i]].front();
v[h]=1;
sh[h]--;
d[MAXN-s[i]].pop_front();
if(s[i]>0&&(i+cont)%2==1)ans+=h-i-1;
else if(s[i]<0&&(i+cont)%2==0)ans+=h-i-1;
else if(s[i]>0&&(i+cont)%2==0)ans+=h-i;
else ans+=h-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... |