#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
const long long inff = 1e18;
struct node {
long long val, lz, lb, ub;
int st, en;
node *left, *right;
void build(int start, int end) {
st = start;
en = end;
lz = 0;
lb = -inf;
ub = inf;
if (st == en) {
val = 0;
return;
}
int md = (st + en) / 2;
left = new node();
right = new node();
left->build(st, md);
right->build(md + 1, en);
}
void lazy() {
left->val += lz;
left->lz += lz;
left->lb += lz;
left->ub += lz;
left->val = max(left->val, lb);
left->lb = max(left->lb, lb);
left->ub = max(left->ub, lb);
left->val = min(left->val, ub);
left->lb = min(left->lb, ub);
left->ub = min(left->ub, ub);
right->val += lz;
right->lz += lz;
right->lb += lz;
right->ub += lz;
right->val = max(right->val, lb);
right->lb = max(right->lb, lb);
right->ub = max(right->ub, lb);
right->val = min(right->val, ub);
right->lb = min(right->lb, ub);
right->ub = min(right->ub, ub);
lz = 0;
lb = -inff;
ub = inff;
}
long long query(int id) {
if (st > id || en < id) return 0ll;
if (st == en) return val;
lazy();
return left->query(id) + right->query(id);
}
void update(int lf, int rg, int x) {
if (st > rg || en < lf) return;
if (lf <= st && en <= rg) {
val += x;
lz += x;
lb += x;
rb += x;
return;
}
lazy();
left->update(lf, rg, x);
right->update(lf, rg, x);
}
void update2(int lf, int rg, long long x, long long y) {
if (st > rg || en < lf) return;
if (lf <= st && en <= rg) {
val = max(val, x);
lb = max(lb, x);
ub = max(ub, x);
val = min(val, y);
lb = min(lb, y);
ub = min(ub, y);
return;
}
lazy();
left->update2(lf, rg, x, y);
right->update2(lf, rg, x, y);
}
} sg;
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = c.size(), q = (int)l.size();
vector<int> s(n);
sg.build(0, n - 1);
for (int i = 0; i < q; i++) {
sg.update(l[i], r[i], v[i]);
sg.update2(0, n - 1, 0, c[0]);
}
for (int i = 0; i < n; i++) {
s[i] = sg.query(i);
}
return s;
}
Compilation message
candies.cpp: In member function 'void node::build(int, int)':
candies.cpp:17:15: error: 'inf' was not declared in this scope; did you mean 'inff'?
17 | lb = -inf;
| ^~~
| inff
candies.cpp: In member function 'void node::update(int, int, int)':
candies.cpp:76:13: error: 'rb' was not declared in this scope; did you mean 'lb'?
76 | rb += x;
| ^~
| lb