summaryrefslogtreecommitdiff
path: root/datastructures/test/segmentTree.cpp
blob: 79c16e6095225e5ef96c87af21c34c2b5785b7ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "segmentTree.tmp.cpp"

void test(int n) {
	vector<ll> a(n);
	for (ll &x: a) x = util::randint();
	SegTree seg(a);
	for (int i = 0; i < 5*n; i++) {
		{
			int j = util::randint(n);
			ll v = util::randint();
			a[j] = v;
			seg.update(j, v);
		}
		{
			int l = util::randint(n+1);
			int r = util::randint(n+1);
			if (l > r) swap(l, r);
			assert(
				seg.query(l, r)
				==
				accumulate(a.begin() + l, a.begin() + r, 0ll)
			);
		}
	}
}

int main() {
	test(1000);
	test(1);
}