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;
typedef long long ll;
const int MAXN=100050;
int n,pt=0,bit[MAXN];
bool used[MAXN],rrl[MAXN];
queue<int> pos[MAXN],neg[MAXN];
ll ans;
ll query(int num){
ll ret=0;
for (int i=num;i;i-=(i&-i)){
ret+=bit[i];
}
return ret;
}
void add(int num){
for (int i=num;i<=n;i+=(i&-i)){
bit[i]++;
}
}
long long count_swaps(std::vector<int> s) {
n=s.size();
for (int i=0;i<n;i++){
if (s[i]>0) pos[s[i]].push(i);
else neg[-s[i]].push(i);
}
for (int i=0;i<n;i++){
if (used[i]) continue;
rrl[pt++]=neg[abs(s[i])].front();
used[neg[abs(s[i])].front()]=1;
rrl[pt++]=pos[abs(s[i])].front();
used[pos[abs(s[i])].front()]=1;
}
for (int i=n-1;i>=0;i--){
ans+=query(rrl[i]);
add(rrl[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... |