From d6d3b6183df2e1d40154f406916993f9b15b3cae Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sun, 28 Apr 2024 03:26:45 +0200 Subject: improve sparse tables --- datastructures/test/sparseTableDisjoint.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 datastructures/test/sparseTableDisjoint.cpp (limited to 'datastructures/test/sparseTableDisjoint.cpp') diff --git a/datastructures/test/sparseTableDisjoint.cpp b/datastructures/test/sparseTableDisjoint.cpp new file mode 100644 index 0000000..43c6d6e --- /dev/null +++ b/datastructures/test/sparseTableDisjoint.cpp @@ -0,0 +1,24 @@ +#include "../sparseTableDisjoint.cpp" + +void test(int n) { + vector values(n); + for (ll &x: values) x = util::randint(); + DisjointST st; + st.init(values); + for (int i = 0; i < n; i++) { + int l = util::randint(n); + int r = util::randint(n); + if (l > r) swap(l, r); + r++; + assert( + st.query(l, r) + == + accumulate(values.begin()+l, values.begin()+r, 0ll) + ); + } +} + +int main() { + test(1000); + test(1); +} -- cgit v1.2.3