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;
long long fen[500000];
void upd(long long x,long long v) {
x++;
while(x<500000) {
fen[x]+=v;
x+=x&(-x);
}
}
long long ask(long long x) {
x++;
long long sum=0;
while(x>0) {
sum+=fen[x];
x-=x&(-x);
}
return sum;
}
long long count_swaps(vector<int> s) {
int n=s.size();
long long ans=0;
map<int,deque<int>>m;
for(int i=0;i<n;i++) {
m[s[i]].push_back(i);
}
for(int i=0;i<n;i++) {
while(m[s[i]].size()>0) {
int ind=m[-abs(s[i])].front();
int indsecond=m[abs(s[i])].front();
ans+=abs(ind-indsecond);
if(ind<indsecond)ans--;
else ans++;
m[s[i]].pop_front();
m[-s[i]].pop_front();
}
}
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... |