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;
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 += 2){
int pos, req;
if(a[i] < 0) {
pos = *R[-a[i]].begin();
L[-a[i]].erase(i);
R[-a[i]].erase(pos);
req = i+1;
}
else {
pos = *L[a[i]].begin();
R[a[i]].erase(i);
L[a[i]].erase(pos);
req = i;
}
for(int j = pos - 1; j > i; j--) {
if(a[j] < 0) {
L[-a[j]].erase(j);
L[-a[j]].insert(j+1);
}
else {
R[a[j]].erase(j);
R[a[j]].insert(j+1);
}
}
for(int j = pos; j > req; j--) {
ans++;
swap(a[j], a[j-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... |