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>
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
const ll N = 2e5+10;
const ll inf = 1e9+100;
const double eps = 1;
int n, a[N];
set<int> L[N], R[N];
ll ans;
bool used[N];
long long count_swaps(std::vector<int> s) {
/*for(int c : s) printf("%d ", c);
printf("\n");*/
ans = 0;
n = s.size();
for(int i = 1;i <= n;i++) {
a[i] = s[i-1];
if(a[i] < 0) L[-a[i]].insert(i);
else R[a[i]].insert(i);
}
/*for(int i = 1; i <= 2; i++) {
printf("left %d:", i);
for(int c : L[i]) printf("%d ", c);
printf("\n");
}
for(int i = 1; i <= 2; i++) {
printf("right %d:", i);
for(int c : R[i]) printf("%d ", c);
printf("\n");
}*/
for(int i = 1; i <= n; i++){
if(used[i]) continue;
int pos;
if(a[i] < 0) {
pos = *R[-a[i]].begin();
L[-a[i]].erase(i);
R[-a[i]].erase(pos);
ans += pos - i - 1;
used[pos] = used[i] = 1;
}
else {
pos = *L[a[i]].begin();
R[a[i]].erase(i);
L[a[i]].erase(pos);
ans += pos - i;
used[pos] = used[i] = 1;
}
}
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... |