Submission #544660

#TimeUsernameProblemLanguageResultExecution timeMemory
544660pokmui9909수족관 3 (KOI13_aqua3)C++17
100 / 100
163 ms44708 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define x first #define y second const ll INF = 1e15; const ll S = (1 << 18); struct MinSeg{ pair<ll, ll> T[2 * S] = {}; MinSeg(){fill(T, T + 2 * S, make_pair(INF, INF)); } void update(ll k, pair<ll, ll> v) { update(1, 1, S, k, v); } pair<ll, ll> query(ll l, ll r) { return query(1, 1, S, l, r); } void update(ll node, ll s, ll e, ll k, pair<ll, ll> v){ if(s == e){ T[node] = min(T[node], v); return; } ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2; if(k <= m) update(lch, s, m, k, v); else update(rch, m + 1, e, k, v); T[node] = min(T[lch], T[rch]); } pair<ll, ll> query(ll node, ll s, ll e, ll l, ll r){ if(r < s || e < l) return {INF, INF}; if(l <= s && e <= r) return T[node]; ll lch = 2 * node, rch = 2 * node + 1, m = (s + e) / 2; pair<ll, ll> x = query(lch, s, m, l, r); pair<ll, ll> y = query(rch, m + 1, e, l, r); return min(x, y); } }; MinSeg ST; struct Data{ ll l, r, w, t; bool operator < (const Data &t) const{ if(l != t.l) return l < t.l; else return r < t.r; } }; ll N, K, M; pair<ll, ll> P[300005]; Data V[300005]; priority_queue<ll> PQ; ll dnc(ll l, ll r, ll s){ if(l > r) return 0; ll mn = ST.query(l, r).first, idx = ST.query(l, r).second; ll v = (mn - s) * (V[r].r - V[l].l); ll p = dnc(l, idx - 1, mn); ll q = dnc(idx + 1, r, mn); PQ.push(min(p, q)); return max(p, q) + v; } int main(){ cin.tie(0) -> sync_with_stdio(false); cin >> N; for(int i = 1; i <= N; i++){ cin >> P[i].x >> P[i].y; if(i % 2 == 1 && i != 1){ V[i / 2] = {P[i - 1].x, P[i].x, P[i].y, 0}; M++; } } cin >> K; for(int i = 1; i <= M; i++){ ST.update(i, {V[i].w, i}); } PQ.push(dnc(1, M, 0)); ll ans = 0; while(!PQ.empty() && K--){ ans += PQ.top(); PQ.pop(); } cout << ans; }
#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...