aboutsummaryrefslogtreecommitdiff
path: root/Data Structures
diff options
context:
space:
mode:
authorAnthony Wang2020-09-21 12:39:40 -0500
committerAnthony Wang2020-09-21 12:39:40 -0500
commit9eff1f7eea32d397c05509ad7fc45297c33866c1 (patch)
tree209f697571e6f11dd860779c5713643a09e413f9 /Data Structures
parent38b999de0298946fecd9f8e1539f99c22190d052 (diff)
Cleanup
Diffstat (limited to 'Data Structures')
-rw-r--r--Data Structures/segment_tree.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/Data Structures/segment_tree.cpp b/Data Structures/segment_tree.cpp
index c0f317b..a52502f 100644
--- a/Data Structures/segment_tree.cpp
+++ b/Data Structures/segment_tree.cpp
@@ -6,8 +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 = -1, int n = 1) {
- if (r == -1) r = N-1;
+ void build(T v, int l = 0, int r = MX, int n = 1) {
if (l == r) seg[n] = v;
else {
int m = (l+r)>>1;
@@ -15,8 +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 = -1, int n = 1) {
- if (r == -1) r = N-1;
+ void update(int x, T v, int l = 0, int r = MX, int n = 1) {
if (l == r) seg[n] += v;
else {
int m = (l+r)>>1;
@@ -24,8 +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 = -1, int n = 1) {
- if (r == -1) r = N-1;
+ void update(int a, int b, T v, int l = 0, int r = MX, int n = 1) {
push(l, r, n);
if (l > r || l > b || r < a) return;
if (l >= a && r <= b) {
@@ -38,8 +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 = -1, int n = 1) {
- if (r == -1) r = N - 1;
+ T query(int a, int b, int l = 0, int r = MX, int n = 1) {
if (a > b || l > b || r < a) return 0;
push(l, r, n);
if (l >= a && r <= b) return seg[n];