이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |