Skip to content

Commit bcb0963

Browse files
authored
Update segmentTreeLazy.cpp
1 parent 71fa8e0 commit bcb0963

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

segmentTreeLazy.cpp

+6-15
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
struct Node
33
{
44
public:
5-
ll count;
65
ll num;
7-
8-
Node(ll a,ll b) : num(a), count(b) {}
9-
Node() : num(0), count(1) {}
6+
7+
Node(ll a) : num(a) {}
8+
Node() : num(0) {}
109

1110
void add(ll val)
1211
{
@@ -25,15 +24,7 @@ struct SegmentTree
2524

2625
Node combine (Node a, Node b)
2726
{
28-
if (a.num == b.num)
29-
{
30-
return Node(a.num,a.count+b.count);
31-
}
32-
if (a.num > b.num)
33-
{
34-
return a;
35-
}
36-
return b;
27+
return Node(a.num+b.num);
3728
}
3829

3930
void propogate(ll v, ll start, ll end)
@@ -43,7 +34,7 @@ struct SegmentTree
4334
lazy[2*v] += lazy[v];
4435
lazy[2*v+1] += lazy[v];
4536
}
46-
segment[v].add(lazy[v]);
37+
segment[v].add(lazy[v]*(end - start + 1));
4738
lazy[v] = 0;
4839
}
4940

@@ -84,7 +75,7 @@ struct SegmentTree
8475
propogate(v,start,end);
8576
if (rangeY < start or end < rangeX)
8677
{
87-
return Node(-1,0);
78+
return Node();
8879
}
8980
if (rangeX <= start and end <= rangeY)
9081
{

0 commit comments

Comments
 (0)