Skip to content

Commit

Permalink
fix bugs for lazy_segment_tree and it's test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Python-in-China committed Oct 12, 2024
1 parent 5b61ed8 commit 807a3c7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testLibrary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
- name: Test
run: |
cd library
./test.exe --gtest_repeat=8
./test.exe --gtest_repeat=20
2 changes: 1 addition & 1 deletion library/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ STDCXX ?= c++14

CXX ?= g++

CXXFLAGS = -Wall -Wextra -g -I. -MMD -std=$(STDCXX)
CXXFLAGS = -Wall -Wextra -g -I. -MMD -std=$(STDCXX) -O2

TARGET = test.exe

Expand Down
1 change: 1 addition & 0 deletions library/mrpython/lazy_segment_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class lazy_segment_tree {
n(len),
lazyInit(lazyInitVal),
mergeData(mergeDataFun),
operate(OperateFun),
mergeLazy(mergeTagFun) {
build();
}
Expand Down
7 changes: 4 additions & 3 deletions library/test/lazy_segment_tree/lazy_segment_tree_add_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ TEST(lazy_segment_tree, add) {
if (l > r) std::swap(l, r);
assert(l < r + 1);
if (operator_dist(gen)) {
int ans = std::accumulate(a.begin() + l, a.begin() + r + 1, (unsigned)0);
unsigned ans =
std::accumulate(a.begin() + l, a.begin() + r + 1, (unsigned)0);
EXPECT_EQ(tree.get(l, r + 1), ans);
} else {
unsigned value = val_dist(gen);
for (std::size_t i = l; i < r; ++i) a[i] += value;
tree.set(l, r, value);
for (std::size_t i = l; i < r + 1; ++i) a[i] += value;
tree.set(l, r + 1, value);
}
}
}

0 comments on commit 807a3c7

Please sign in to comment.