Submission #804372

#TimeUsernameProblemLanguageResultExecution timeMemory
804372math_rabbit_1028Distributing Candies (IOI21_candies)C++17
27 / 100
423 ms30476 KiB
#include "candies.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; int c; struct node { ll val; ll add, upp, low; } tree[808080]; node merger(node lt_val, node rt_val) { return {lt_val.val + rt_val.val, 0, c, 0}; } void propagate(int v, int st, int ed) { tree[v].val = max(min(tree[v].val + tree[v].add, tree[v].upp), tree[v].low); if (st != ed) { //c1 = tree[u].upp, d1 = tree[u].add, e1 = tree[u].low //c2 = tree[v].upp, d2 = tree[v].add, e2 = tree[v].low for (auto u : {2 * v, 2 * v + 1}) { tree[u].upp = min(tree[u].upp + tree[v].add, tree[v].upp); tree[u].add = tree[u].add + tree[v].add; tree[u].low = max(min(tree[u].low + tree[v].add, tree[v].upp), tree[v].low); } } tree[v].add = 0; tree[v].upp = c; tree[v].low = 0; } void init(int v, int st, int ed) { if (st == ed) { tree[v].val = 0; tree[v].add = 0; tree[v].upp = c; tree[v].low = 0; return; } int mid = (st + ed) / 2; init(2 * v, st, mid); init(2 * v + 1, mid + 1, ed); tree[v] = merger(tree[2 * v], tree[2 * v + 1]); } void update(int v, int st, int ed, int lt, int rt, int val) { propagate(v, st, ed); if (lt > ed || st > rt) return; if (lt <= st && ed <= rt) { tree[v].add += val; propagate(v, st, ed); return; } int mid = (st + ed) / 2; update(2 * v, st, mid, lt, rt, val); update(2 * v + 1, mid + 1, ed, lt, rt, val); tree[v] = merger(tree[2 * v], tree[2 * v + 1]); } int get(int v, int st, int ed, int idx) { propagate(v, st, ed); if (st > idx || ed < idx) return 0; if (st == idx && ed == idx) return tree[v].val; int mid = (st + ed) / 2; return get(2 * v, st, mid, idx) + get(2 * v + 1, mid + 1, ed, idx); } std::vector<int> distribute_candies(std::vector<int> C, std::vector<int> l, std::vector<int> r, std::vector<int> v) { int n = C.size(); int q = l.size(); std::vector<int> s(n); c = C[0]; init(1, 0, n - 1); for (int i = 0; i < q; i++) { update(1, 0, n - 1, l[i], r[i], v[i]); } for (int i = 0; i < n; i++) { s[i] = get(1, 0, n - 1, i); } return s; }
#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...