# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
632746 | ghostwriter | Arranging Shoes (IOI19_shoes) | C++14 | 74 ms | 20336 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;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
Tran The Bao
CTL - Da Lat
Practising for VOI23 gold medal
*/
const int N = 2e5 + 1;
int n, c[N], f[N];
vi d[N], d1[N];
int get(int ps) { ++ps; int rs = 0; for (int i = ps; i >= 1; i -= (i & -i)) rs += f[i]; return rs; }
void upd(int ps, int v) { ++ps; for (int i = ps; i <= n + 1; i += (i & -i)) f[i] += v; }
long long count_swaps(std::vector<int> s) {
n = sz(s) - 1;
FOS(i, n, 0)
if (s[i] < 0) d[-s[i]].pb(i);
else d1[s[i]].pb(i);
ll rs = 0;
FOR(i, 0, n) {
if (c[i]) continue;
int ss = abs(s[i]);
if (s[i] < 0) {
int pos = d1[ss].back();
c[pos] = 1;
d1[ss]._pb();
rs += pos - i - 1 - get(pos) + get(i);
d[ss]._pb();
upd(pos, 1);
}
else {
int pos = d[ss].back();
c[pos] = 1;
d[ss]._pb();
rs += pos - i - get(pos) + get(i);
d1[ss]._pb();
upd(pos, 1);
}
}
return rs;
}
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... |