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>
#define ll long long
using namespace std;
int F[200007], sz, N;
void upd(int i, int x){
i++;
for(; i<=sz; i+=(i&-i))
F[i]+=x;
}
int pre(int i){
i++;
int ret=0;
for(; i>0; i-=(i&-i))
ret+=F[i];
return ret;
}
long long count_swaps(std::vector<int> s) {
ll ret=0;
sz=s.size(), N=sz/2;
queue<int> cnt[sz+1];
bool udh[sz];
for(int i=0; i<sz; i++){
s[i]+=N;
cnt[s[i]].push(i);
upd(i, 1);
}
memset(udh, 0, sizeof(udh));
for(int i=0, j; i<sz; i++){
if(udh[i])
continue;
j=cnt[N-s[i]+N].front();
cnt[N-s[i]+N].pop();
cnt[s[i]].pop();
udh[i]=1, udh[j]=1;
ret+=pre(j-1);
if(s[i]<N)
ret--;
upd(i, -1);
upd(j, -1);
//cout << i << ' ' << ret << endl;
}
return ret;
}
# | 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... |