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>
#define ll long long
#define pb push_back
using namespace std;
const ll N = 2e5 + 100;
vector<ll> x[N], e[N];
ll nw[N];
ll px[N], py[N];
long long count_swaps(vector<int> s) {
ll n = s.size();
for(int i = 1; i <= n; i++)
if(s[i - 1] < 0) {
x[-s[i - 1]].pb(i);
}
else {
e[s[i - 1]].pb(i);
}
ll ans = 0, cur = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < (ll)e[i].size(); j++) {
if(x[i][j] < e[i][j])
nw[x[i][j]] = cur, nw[e[i][j]] = -cur;
else
nw[x[i][j]] = -cur, nw[e[i][j]] = cur, ans++;
cur++;
}
}
for(int j = n; j >= 1; j -= 2) {
ll z = -nw[j];
ll h = j - 1;
while(nw[h] != z)
h--;
while(h < j - 1) {
swap(nw[h], nw[h + 1]), h++;
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... |