11#pragma once
22#include " seg_tree_midpoint.hpp"
3- ll op (ll vl, ll vr) { return vl + vr; }
43struct seg_tree {
4+ ll op (ll vl, ll vr) { return vl + vr; }
55 int n;
66 vector<ll> tree, lazy;
77 seg_tree (int n): n(n), tree(2 * n), lazy(n) {}
@@ -11,9 +11,9 @@ struct seg_tree {
1111 for (int i = n - 1 ; i >= 1 ; i--)
1212 tree[i] = op (tree[2 * i], tree[2 * i + 1 ]);
1313 }
14- void apply (ll change , int tl, int tr, int v) {
15- tree[v] += (tr - tl + 1 ) * change ;
16- if (v < n) lazy[v] += change ;
14+ void apply (ll d , int tl, int tr, int v) {
15+ tree[v] += (tr - tl + 1 ) * d ;
16+ if (v < n) lazy[v] += d ;
1717 }
1818 void push (int tl, int tm, int tr, int v) {
1919 if (lazy[v]) {
@@ -22,18 +22,16 @@ struct seg_tree {
2222 lazy[v] = 0 ;
2323 }
2424 }
25- void update (int l, int r, ll change ) {
26- update (l, r, change , 0 , n - 1 , 1 );
25+ void update (int l, int r, ll d ) {
26+ update (l, r, d , 0 , n - 1 , 1 );
2727 }
28- void update (int l, int r, ll change, int tl, int tr,
29- int v) {
28+ void update (int l, int r, ll d, int tl, int tr, int v) {
3029 if (r < tl || tr < l) return ;
31- if (l <= tl && tr <= r)
32- return apply (change, tl, tr, v);
30+ if (l <= tl && tr <= r) return apply (d, tl, tr, v);
3331 int tm = split (tl, tr);
3432 push (tl, tm, tr, v);
35- update (l, r, change , tl, tm, 2 * v);
36- update (l, r, change , tm + 1 , tr, 2 * v + 1 );
33+ update (l, r, d , tl, tm, 2 * v);
34+ update (l, r, d , tm + 1 , tr, 2 * v + 1 );
3735 tree[v] = op (tree[2 * v], tree[2 * v + 1 ]);
3836 }
3937 ll query (int l, int r) {
0 commit comments