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>
#include "shoes.h"
using namespace std;
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
set<int> L[200005], R[200005];
int vis[200005];
long long count_swaps(std::vector<int> s) {
int n = (int)s.size();
for(int i=0;i<n;i++){
if(s[i] < 0)L[-s[i]].insert(i);
else R[s[i]].insert(i);
}
long long ans = 0;
int cnt = 0;
for(int i=0;i<n;i++){
if(vis[i])continue;
if(s[i] < 0){
L[-s[i]].erase(L[-s[i]].begin());
ans += max(0, *R[-s[i]].begin() - cnt * 2 - 1);
vis[*R[-s[i]].begin()] = 1;
R[-s[i]].erase(R[-s[i]].begin());
}
else{
ans++;
R[s[i]].erase(R[s[i]].begin());
ans += max(0, *L[s[i]].begin() - cnt * 2 - 1);
vis[*L[s[i]].begin()] = 1;
L[s[i]].erase(L[s[i]].begin());
}
cnt++;
}
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... |