이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// In the name of Allah
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<ld> cld;
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
#define F first
#define S second
#define pb push_back
#define sep ' '
#define endl '\n'
#define Mp make_pair
#define kill(x) cout << x << '\n', exit(0)
#define set_dec(x) cout << fixed << setprecision(x);
#define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 7;
int n, sz;
vector<int> ls1[maxn], ls2[maxn];
pii val[maxn]; int arr[maxn];
ll t[maxn];
bool cmp(pii a, pii b) {
return (min(a.F, a.S) < min(b.F, b.S));
}
void addx(int i, ll x) {
for (++i; i <= 2 * n; i += (i & -i)) t[i] += x;
}
ll getx(int i) {
ll res = 0;
for (++i; i > 0; i -= (i & -i)) res += t[i];
return res;
}
ll get_inv() {
ll res = 0;
for (int i = 2 * n - 1; i >= 0; i--) {
res += getx(arr[i]);
addx(arr[i], 1);
}
return res;
}
ll count_swaps(vector<int> s) {
n = len(s) / 2;
for (int i = 0; i < 2 * n; i++) {
int j = abs(s[i]) - 1;
if (s[i] < 0) ls1[j].pb(i);
else ls2[j].pb(i);
}
int sz = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < len(ls1[i]); j++) {
val[sz] = Mp(ls1[i][j], ls2[i][j]);
sz++;
}
}
sort(val, val + n, cmp);
for (int i = 0; i < 2 * n; i += 2) {
arr[i] = val[i / 2].F; arr[i + 1] = val[i / 2].S;
}
return get_inv();
}
# | 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... |