Submission #593373

#TimeUsernameProblemLanguageResultExecution timeMemory
593373TemmieSeats (IOI18_seats)C++17
70 / 100
4037 ms126828 KiB
#include <bits/stdc++.h> constexpr const int mxn = 1e6 + 3; struct Seg { int size; int res[mxn << 2], min[mxn << 2], laz[mxn << 2]; Seg() = default; Seg(int s) { memset(res, 0, sizeof(res)); memset(min, 0, sizeof(min)); memset(laz, 0, sizeof(laz)); size = s; build(0, 0, size); } void build(int now, int l, int r) { if (!(r - l - 1)) { res[now] = 1; return; } int mid = (l + r) >> 1; build(now * 2 + 1, l, mid); build(now * 2 + 2, mid, r); res[now] = res[now * 2 + 1] + res[now * 2 + 2]; } inline void push(int now, int l, int r) { min[now] += laz[now]; if (r - l - 1) { laz[now * 2 + 1] += laz[now]; laz[now * 2 + 2] += laz[now]; } laz[now] = 0; } inline void update(int l, int r, int val) { if (r <= l) { return; } update(l, r, val, 0, 0, size); } void update(int tl, int tr, int val, int now, int l, int r) { if (l >= tr || r <= tl) { return; } if (l >= tl && r <= tr) { laz[now] += val; return; } push(now, l, r); int mid = (l + r) >> 1; update(tl, tr, val, now * 2 + 1, l, mid); update(tl, tr, val, now * 2 + 2, mid, r); push(now * 2 + 1, l, mid); push(now * 2 + 2, mid, r); min[now] = std::min(min[now * 2 + 1], min[now * 2 + 2]); res[now] = (min[now * 2 + 1] == min[now] ? res[now * 2 + 1] : 0) + (min[now * 2 + 2] == min[now] ? res[now * 2 + 2] : 0); } inline int query() { push(0, 0, size); return min[0] == 4 ? res[0] : 0; } } seg; int n, m, k; std::vector <int> g; int inv[mxn]; inline void fix(int i, int j, int val) { static int vals[4]; vals[0] = g[i * k + j]; vals[1] = g[(i + 1) * k + j]; vals[2] = g[i * k + j + 1]; vals[3] = g[(i + 1) * k + j + 1]; std::sort(vals, vals + 4); seg.update(vals[0], vals[1], val); seg.update(vals[2], vals[3], val); } void give_initial_chart(int h, int w, std::vector <int> r, std::vector <int> c) { n = h; m = w; k = m + 2; seg = Seg(n * m); g.resize((n + 2) * (m + 2), n * m); for (int i = 0; i < n * m; i++) { inv[i] = ++r[i] * k + ++c[i]; g[r[i] * k + c[i]] = i; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= m; j++) { fix(i, j, 1); } } } int swap_seats(int a, int b) { std::pair <int, int> av = { inv[a] / k, inv[a] % k }; std::pair <int, int> bv = { inv[b] / k, inv[b] % k }; for (int di = 0; di <= 1; di++) { for (int dj = 0; dj <= 1; dj++) { fix(av.first - di, av.second - dj, -1); fix(bv.first - di, bv.second - dj, -1); } } std::swap(g[inv[a]], g[inv[b]]); std::swap(inv[a], inv[b]); for (int di = 0; di <= 1; di++) { for (int dj = 0; dj <= 1; dj++) { fix(av.first - di, av.second - dj, 1); fix(bv.first - di, bv.second - dj, 1); } } return seg.query(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...