diff options
author | Anthony Wang | 2020-09-21 12:43:51 -0500 |
---|---|---|
committer | Anthony Wang | 2020-09-21 12:43:51 -0500 |
commit | 57c74f6551b098e0d87cbe75b2a03ed0147995a6 (patch) | |
tree | a30d0a0f95531e992b46477cb30f867deaabbe7d /Data Structures | |
parent | b2a014f4fe941e62fba10c801981cb5e8448835c (diff) |
Minor bug
Diffstat (limited to 'Data Structures')
-rw-r--r-- | Data Structures/segment_tree.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Data Structures/segment_tree.cpp b/Data Structures/segment_tree.cpp index a52502f..b7c6e05 100644 --- a/Data Structures/segment_tree.cpp +++ b/Data Structures/segment_tree.cpp @@ -6,7 +6,7 @@ template<typename T> struct seg_tree { if (l != r) tmp[n<<1] += tmp[n], tmp[n<<1|1] += tmp[n]; tmp[n] = 0; } - void build(T v, int l = 0, int r = MX, int n = 1) { + void build(T v, int l = 0, int r = MX-1, int n = 1) { if (l == r) seg[n] = v; else { int m = (l+r)>>1; @@ -14,7 +14,7 @@ template<typename T> struct seg_tree { seg[n] = pull(seg[n<<1], seg[n<<1|1]); } } - void update(int x, T v, int l = 0, int r = MX, int n = 1) { + void update(int x, T v, int l = 0, int r = MX-1, int n = 1) { if (l == r) seg[n] += v; else { int m = (l+r)>>1; @@ -22,7 +22,7 @@ template<typename T> struct seg_tree { seg[n] = pull(seg[n<<1], seg[n<<1|1]); } } - void update(int a, int b, T v, int l = 0, int r = MX, int n = 1) { + void update(int a, int b, T v, int l = 0, int r = MX-1, int n = 1) { push(l, r, n); if (l > r || l > b || r < a) return; if (l >= a && r <= b) { @@ -35,7 +35,7 @@ template<typename T> struct seg_tree { seg[n] = pull(seg[n<<1], seg[n<<1|1]); } } - T query(int a, int b, int l = 0, int r = MX, int n = 1) { + T query(int a, int b, int l = 0, int r = MX-1, int n = 1) { if (a > b || l > b || r < a) return 0; push(l, r, n); if (l >= a && r <= b) return seg[n]; |