# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143587 | kdh9949 | Arranging Shoes (IOI19_shoes) | C++17 | 136 ms | 27004 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];
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;
int c = 0;
for(int i = 0; i < 2 * n; i++){
(s[i] < 0 ? u : v)[abs(s[i])].pb(i);
if(s[i] < 0) t[-s[i]].pb(++c);
}
for(int i = 1; i <= n; i++){
for(int j = 0; j < u[i].size(); j++){
a[u[i][j]] = 2 * t[i][j] - 1;
a[v[i][j]] = 2 * t[i][j];
}
}
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... |