From cd870938f6cf266292e0e5cecb2d96d604b2ad9d Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Sun, 10 Mar 2024 20:48:51 +0100 Subject: make Fenwick Tree prefix sum exclusive --- datastructures/test/fenwickTree.cpp | 4 ++-- datastructures/test/fenwickTree2.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'datastructures/test') diff --git a/datastructures/test/fenwickTree.cpp b/datastructures/test/fenwickTree.cpp index 4bc812a..f9dd619 100644 --- a/datastructures/test/fenwickTree.cpp +++ b/datastructures/test/fenwickTree.cpp @@ -10,10 +10,10 @@ void test(int n) { update(p, delta); naive[p] += delta; - int r = util::randint(n+1) - 1; + int r = util::randint(n+1); ll naive_result = 0; - for (int i = 0; i <= r; i++) naive_result += naive[i]; + for (int i = 0; i < r; i++) naive_result += naive[i]; ll fenwick_result = prefix_sum(r); assert(naive_result == fenwick_result); } diff --git a/datastructures/test/fenwickTree2.cpp b/datastructures/test/fenwickTree2.cpp index 359a5c4..18ebcb7 100644 --- a/datastructures/test/fenwickTree2.cpp +++ b/datastructures/test/fenwickTree2.cpp @@ -12,10 +12,10 @@ void test(int n) { update(l, r, delta); for (int i = l; i < r; i++) naive[i] += delta; - r = util::randint(n+1) - 1; + r = util::randint(n+1); ll naive_result = 0; - for (int i = 0; i <= r; i++) naive_result += naive[i]; + for (int i = 0; i < r; i++) naive_result += naive[i]; ll fenwick_result = prefix_sum(r); assert(naive_result == fenwick_result); } -- cgit v1.2.3