summaryrefslogtreecommitdiff
path: root/datastructures/test/sparseTableDisjoint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'datastructures/test/sparseTableDisjoint.cpp')
-rw-r--r--datastructures/test/sparseTableDisjoint.cpp24
1 files changed, 24 insertions, 0 deletions
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<ll> 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);
+}