# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143592 | kdh9949 | Arranging Shoes (IOI19_shoes) | C++17 | 116 ms | 24852 KiB |
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>
using namespace std;
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define cppio ios_base::sync_with_stdio(0);cin.tie(0)
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 200005;
vector<int> u[N], v[N], t[N];
vector<pii> w;
int a[N];
struct BIT{
int d[N];
void u(int x){ for(; x < N; x += x & -x) d[x]++; }
int g(int x){ int r = 0; for(; x; x -= x & -x) r += d[x]; return r; }
int g(int s, int e){ return g(e) - g(s - 1); }
} B;
ll count_swaps(vector<int> s) {
int n = s.size() / 2;
for(int i = 0; i < 2 * n; i++) (s[i] < 0 ? u : v)[abs(s[i])].pb(i);
for(int i = 1; i <= n; i++) for(int j = 0; j < u[i].size(); j++) w.pb(pii(u[i][j], v[i][j]));
sort(all(w), [](pii x, pii y){ return x.x + x.y < y.x + y.y; });
for(int i = 0; i < n; i++){
a[w[i].x] = 2 * i + 1;
a[w[i].y] = 2 * i + 2;
}
ll r = 0;
for(int i = 0; i < 2 * n; i++){
r += B.g(a[i] + 1, 2 * n);
B.u(a[i]);
}
return r;
}
Compilation message (stderr)
# | 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... |