Submission #620003

#TimeUsernameProblemLanguageResultExecution timeMemory
620003evenvalueSeats (IOI18_seats)C++17
17 / 100
4091 ms55632 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>; using int64 = long long; using ld = long double; constexpr int kInf = 1e9 + 10; constexpr int64 kInf64 = 1e15 + 10; constexpr int kMod = 1e9 + 7; template<class node, class F = std::function<node(const node &, const node &)>> class SegTree { int n = 0; std::vector<node> t; F unite; void build(const int x, const int l, const int r, const std::vector<node> &a) { if (l == r) { t[x] = a[l]; return; } const int mid = (l + r) / 2; const int y = 2 * (mid - l + 1) + x; build(x + 1, l, mid, a); build(y, mid + 1, r, a); t[x] = unite(t[x + 1], t[y]); } void update(const int x, const int l, const int r, const int p, const node &v) { if (l == p and p == r) { t[x] = v; return; } const int mid = (l + r) / 2; const int y = 2 * (mid - l + 1) + x; if (p <= mid) { update(x + 1, l, mid, p, v); } else { update(y, mid + 1, r, p, v); } t[x] = unite(t[x + 1], t[y]); } node query(const int x, const int l, const int r, const int ql, const int qr) const { if (ql <= l and r <= qr) { return t[x]; } const int mid = (l + r) / 2; const int y = 2 * (mid - l + 1) + x; if (qr <= mid) { return query(x + 1, l, mid, ql, qr); } else if (mid < ql) { return query(y, mid + 1, r, ql, qr); } else { return unite(query(x + 1, l, mid, ql, qr), query(y, mid + 1, r, ql, qr)); } } public: SegTree() = default; explicit SegTree(const int n, const node e, F f) : n(n), t(2 * n - 1, e), unite(std::move(f)) {} explicit SegTree(const std::vector<node> &a, F f) : n(a.size()), t(2 * (a.size()) - 1), unite(std::move(f)) { build(0, 0, n - 1, a); } void set(const int p, const node &v) { assert(0 <= p and p < n); update(0, 0, n - 1, p, v); } node get(const int l, const int r) const { assert(0 <= l and l <= r and r < n); return query(0, 0, n - 1, l, r); } }; struct MinimumBoundingRectangle { int l = -1, r = -1, t = -1, b = -1; }; int H, W, contestants; vector<int> R, C; vector<MinimumBoundingRectangle> pref; SegTree<int> st; void give_initial_chart(int H_, int W_, std::vector<int> R_, std::vector<int> C_) { H = H_, W = W_; contestants = H * W; R = move(R_), C = move(C_); pref.resize(contestants, {C[0], C[0], R[0], R[0]}); st = SegTree<int>(contestants, 0, [](const int l, const int r) { return l + r; }); st.set(0, 1); for (int i = 1; i < contestants; i++) { pref[i] = pref[i - 1]; auto &[l, r, t, b] = pref[i]; l = min(pref[i].l, C[i]); r = max(pref[i].r, C[i]); t = min(pref[i].t, R[i]); b = max(pref[i].b, R[i]); const int rect_size = (r - l + 1) * (b - t + 1); if (i + 1 == rect_size) st.set(i, 1); } } int swap_seats(int x, int y) { if (x > y) swap(x, y); swap(C[x], C[y]); swap(R[x], R[y]); for (int i = x; i <= y; i++) { pref[i] = (i == 0 ? MinimumBoundingRectangle({C[0], C[0], R[0], R[0]}) : pref[i - 1]); auto &[l, r, t, b] = pref[i]; l = min(pref[i].l, C[i]); r = max(pref[i].r, C[i]); t = min(pref[i].t, R[i]); b = max(pref[i].b, R[i]); const int rect_size = (r - l + 1) * (b - t + 1); st.set(i, (rect_size == i + 1)); } return st.get(0, contestants - 1); }
#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...