| 10 | int rsq(int a, int b) { return query(b) - query(a - 1); } |
| 11 | }; |
| 12 | struct fenwick_tree_sq { |
| 13 | int n; fenwick_tree x1, x0; |
| 14 | fenwick_tree_sq(int _n) : n(_n), x1(fenwick_tree(n)), |
| 15 | x0(fenwick_tree(n)) { } |
| 16 | // insert f(y) = my + c if x <= y |
| 17 | void update(int x, int m, int c) { |
| 18 | x1.update(x, m); x0.update(x, c); } |
| 19 | int query(int x) { return x*x1.query(x) + x0.query(x); } |
| 20 | }; |
| 21 | void range_update(fenwick_tree_sq &s, int a, int b, int k) { |
| 22 | s.update(a, k, k * (1 - a)); s.update(b+1, -k, k * b); } |
| 23 | int range_query(fenwick_tree_sq &s, int a, int b) { |
nothing calls this directly
no outgoing calls
no test coverage detected