제출 #950513

#제출 시각아이디문제언어결과실행 시간메모리
950513arbuzickGarden (JOI23_garden)C++17
30 / 100
3081 ms4440 KiB
#include <bits/stdc++.h> using namespace std; struct Node { int mx_pref, mx_suff, mx_segm, len; Node(int _len = 0, int _val = 0) { mx_pref = mx_suff = mx_segm = _val; len = _len; } Node operator+(Node b) { Node ans; ans.len = len + b.len; if (mx_pref == len) { ans.mx_pref = len + b.mx_pref; } else { ans.mx_pref = mx_pref; } if (b.mx_suff == b.len) { ans.mx_suff = b.len + mx_suff; } else { ans.mx_suff = b.mx_suff; } ans.mx_segm = max(mx_suff + b.mx_pref, max(mx_segm, b.mx_segm)); return ans; } }; constexpr int R = 1 << 13; Node tree[R * 2]; void build(int d) { for (int i = 0; i < d; ++i) { tree[i + R] = Node(1, 1); } for (int i = R - 1; i > 0; --i) { tree[i] = tree[i * 2] + tree[i * 2 + 1]; } } void change(int pos, int val) { pos += R; tree[pos] = Node(1, val); for (pos /= 2; pos > 0; pos /= 2) { tree[pos] = tree[pos * 2] + tree[pos * 2 + 1]; } } void solve() { int n, m, d; cin >> n >> m >> d; vector<int> p(n), q(n); for (int i = 0; i < n; ++i) { cin >> p[i] >> q[i]; } vector<int> r(m), s(m); for (int i = 0; i < m; ++i) { cin >> r[i] >> s[i]; } int ans = d * d; if (false && m <= 8) { vector<int> p_nw, q_nw; for (int i = 0; i < n; ++i) { p_nw.push_back(p[i]); p_nw.push_back(p[i] + d); q_nw.push_back(q[i]); q_nw.push_back(q[i] + d); } sort(p_nw.begin(), p_nw.end()); sort(q_nw.begin(), q_nw.end()); for (int mask = 0; mask < (1 << m); ++mask) { int mnx = d, mny = d; for (int i = 0; i < d; ++i) { int posx = lower_bound(p_nw.begin(), p_nw.end(), i) - p_nw.begin(); int rx = p_nw[posx + n - 1] + 1; for (int j = 0; j < m; ++j) { if (mask & (1 << j)) { if (i <= r[j]) { rx = max(rx, r[j] + 1); } else { rx = max(rx, r[j] + d + 1); } } } mnx = min(mnx, rx - i); int posy = lower_bound(q_nw.begin(), q_nw.end(), i) - q_nw.begin(); int ry = q_nw[posy + n - 1] + 1; for (int j = 0; j < m; ++j) { if (!(mask & (1 << j))) { if (i <= s[j]) { ry = max(ry, s[j] + 1); } else { ry = max(ry, s[j] + d + 1); } } } mny = min(mny, ry - i); } ans = min(ans, mnx * mny); } } else { build(d); vector<int> cnt(d); int pos_mn = d, pos_mx = -1; for (int i = 0; i < n; ++i) { pos_mn = min(pos_mn, q[i]); pos_mx = max(pos_mx, q[i]); cnt[q[i]]++; if (cnt[q[i]] == 1) { change(q[i], 0); } } for (int lx = 0; lx < d; ++lx) { int rx = lx + 1; for (int i = 0; i < n; ++i) { if (lx <= p[i]) { rx = max(rx, p[i] + 1); } else { rx = max(rx, p[i] + d + 1); } } vector<int> inds(m); iota(inds.begin(), inds.end(), 0); sort(inds.begin(), inds.end(), [&](int i, int j) { int ri = rx, rj = rx; if (lx <= r[i]) { ri = max(ri, r[i] + 1); } else { ri = max(ri, r[i] + d + 1); } if (lx <= r[j]) { rj = max(rj, r[j] + 1); } else { rj = max(rj, r[j] + d + 1); } return ri < rj; }); int pos_mn_nw = pos_mn, pos_mx_nw = pos_mx; vector<int> rys(m + 1); rys[m] = d - tree[1].mx_segm; for (int i = m - 1; i >= 0; --i) { cnt[s[inds[i]]]++; pos_mn_nw = min(pos_mn_nw, s[inds[i]]); pos_mx_nw = max(pos_mx_nw, s[inds[i]]); if (cnt[s[inds[i]]] == 1) { change(s[inds[i]], 0); } rys[i] = d - tree[1].mx_segm; rys[i] = min(rys[i], pos_mx_nw - pos_mn_nw + 1); } for (int i = 0; i < m; ++i) { ans = min(ans, (rx - lx) * rys[i]); if (lx <= r[inds[i]]) { rx = max(rx, r[inds[i]] + 1); } else { rx = max(rx, r[inds[i]] + d + 1); } } ans = min(ans, (rx - lx) * rys[m]); for (int i = 0; i < m; ++i) { cnt[s[i]]--; if (cnt[s[i]] == 0) { change(s[i], 1); } } } } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#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...