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[2*n]={},x,z,ans=0;
for(long i=0;i<2*n;i++){
m[s[i]].push_back(i);
}
for(long i=0;i<2*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<2*n;j++){
arr[j]--;
}
ans+=x-i-1+arr[x];
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... |