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 count_swaps(std::vector<int> s) {
map<long,vector<long> >m;
map<long,long>now;
map<long,bool>ok;
long n=s.size();
long long arr[n]={},x,z,ans=0;
for(long i=0;i<n;i++){
m[s[i]].push_back(i);
}
for(long i=0;i<n;i++){
if(ok[abs(s[i])]){
ok[abs(s[i])]=false;
}
else{
ok[abs(s[i])]=true;
z=now[abs(s[i])];
x=m[-s[i]][z];
now[abs(s[i])]++;
for(long j=x+1;j<n;j++){
arr[j]--;
}
ans+=x+arr[x]-i-arr[i]-1;
if(s[i]>0){
ans++;
}
}
}
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... |