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 <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define lint long long
using namespace std;
lint count_swaps(vector<int> s){
int n = s.size();
vector<set<int>>set(2*n+1);
vector<bool>ignore(2*n);
rep(i,2*n){
set[s[i]+n].insert(i);
}
int sum=0;
rep(i,2*n){
if(ignore[i]){continue;}
int nearest=*set[-s[i]+n].begin();
set[-s[i]+n].erase(set[-s[i]+n].begin());
ignore[nearest]=true;
if(s[i]>0){sum++;}
sum+=nearest-i-1;
}
return sum;
}
/*
signed main(){
int n;
cin >> n;
vector<int>s(n);
rep(i,n){cin>>s[i];}
cout << count_swaps(s);
}
*/
# | 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... |