제출 #1019927

#제출 시각아이디문제언어결과실행 시간메모리
1019927overwatch9모임들 (IOI18_meetings)C++17
0 / 100
19 ms2648 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; using ll = long long; struct stree { #define lc v*2 #define rc v*2+1 vector <ll> tree; stree (int s) { tree.resize(s * 4, 1e18); } void pushup(int v) { tree[v] = min(tree[lc], tree[rc]); } void update(int v, int tl, int tr, int p, ll val) { if (tl > p || tr < p) return; if (tl == tr) { tree[v] = val; return; } int tm = (tl + tr) / 2; update(lc, tl, tm, p, val); update(rc, tm+1, tr, p, val); pushup(v); } ll query(int v, int tl, int tr, int l, int r) { if (tl > r || tr < l) return 1e18; if (tl >= l && tr <= r) return tree[v]; int tm = (tl + tr) / 2; ll a = query(lc, tl, tm, l, r); ll b = query(rc, tm+1, tr, l, r); return min(a, b); } }; vector<ll> minimum_costs(vector<int> h, vector<int> L, vector<int> R) { int Q = L.size(); int n = h.size(); stree tree(n+1); vector <ll> lsum(n), rsum(n); lsum[0] = h[0]; for (int i = 1; i < n; i++) { lsum[i] = lsum[i-1]; if (h[i] == 2) lsum[i] = (i+1) * 2; else lsum[i]++; } rsum[n-1] = h[n-1]; for (int i = n-2; i >= 0; i--) { rsum[i] = rsum[i+1]; if (h[i] == 2) rsum[i] = (n - i) * 2; else rsum[i]++; } for (int i = 0; i < n; i++) { if (h[i] == 1) tree.update(1, 0, n, i, lsum[i] + rsum[i] - h[i]); // cout << "sum: " << lsum[i] << ' ' << rsum[i] << '\n'; } vector <ll> ans(Q); for (int i = 0; i < Q; i++) { ll x = tree.query(1, 0, n, L[i], R[i]); // cout << "x: " << x << '\n'; x -= lsum[L[i]]; x -= rsum[R[i]]; x += h[L[i]]; x += h[R[i]]; ans[i] = min(x, (ll)(R[i] - L[i] + 1) * 2); } return ans; } // int main() { // int n, q; // cin >> n >> q; // vector <int> h(n); // for (int i = 0; i < n; i++) // cin >> h[i]; // vector <int> l(q), r(q); // for (int i = 0; i < q; i++) // cin >> l[i] >> r[i]; // auto res = minimum_costs(h, l, r); // }
#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...