37# include <gtest/gtest.h>
45using namespace testing;
62 for (
size_t i = 0; i < 5; ++i)
91 std::vector<int> values = {2, 7, 1, 8, 2, 8};
217 int operator()(
int a,
int b)
const noexcept {
return a ^ b; }
226 ft.update(0, 0b1010);
227 ft.update(1, 0b1100);
228 ft.update(2, 0b0110);
250 const size_t N = 1000;
253 std::mt19937
rng(42);
254 std::uniform_int_distribution<size_t>
idx_dist(0,
N - 1);
255 std::uniform_int_distribution<int>
val_dist(-1000, 1000);
258 std::vector<long long>
naive(
N, 0);
260 for (
int op = 0; op <
num_ops; ++op)
270 for (
size_t i = 0; i <
N; ++i)
277 for (
size_t i = 0; i <
N; ++i)
354 for (
int k = 1;
k <= 8; ++
k)
378 const size_t N = 512;
379 std::mt19937
rng(123);
380 std::uniform_int_distribution<int>
val_dist(0, 10);
383 std::vector<int>
naive(
N, 0);
385 for (
size_t i = 0; i <
N; ++i)
393 std::vector<long long>
pfx(
N);
395 for (
size_t i = 1; i <
N; ++i)
403 for (
size_t i = 0; i <
N; ++i)
411 <<
"find_kth(" <<
k <<
") mismatch";
444 for (
size_t i = 0; i < 5; ++i)
512 ft.point_update(0, 5);
513 ft.point_update(1, 3);
514 ft.point_update(2, 7);
515 ft.point_update(3, 2);
556 for (
size_t i = 0; i < 5; ++i)
582 ft2.update(0, 3, 100);
629 const size_t N = 200;
632 std::mt19937
rng(77);
633 std::uniform_int_distribution<size_t>
idx_dist(0,
N - 1);
634 std::uniform_int_distribution<int>
val_dist(-100, 100);
637 std::vector<long long>
naive(
N, 0);
639 for (
int op = 0; op <
num_ops; ++op)
647 ft.update(a, b, delta);
648 for (
size_t i = a; i <= b; ++i)
654 for (
size_t i = 0; i <
N; ++i)
658 <<
"mismatch at prefix(" << i <<
")";
662 for (
size_t i = 0; i <
N; ++i)
664 <<
"mismatch at get(" << i <<
")";
667 for (
int q = 0; q < 500; ++q)
675 for (
size_t i = a; i <= b; ++i)
679 <<
"mismatch at query(" << a <<
", " << b <<
")";
Simple dynamic array with automatic resizing and functional operations.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
Fenwick tree over an arbitrary abelian group.
void swap(Gen_Fenwick_Tree &other) noexcept
Swap this tree with other in O(1).
T prefix(size_t i) const
Prefix query: Plus(a[0], a[1], ..., a[i]).
constexpr size_t size() const noexcept
Number of logical elements.
constexpr bool is_empty() const noexcept
Return true if list is empty.
size_t size() const noexcept
Count the number of elements of the list.
Fenwick tree supporting range updates and range queries.
void swap(Range_Fenwick_Tree &other) noexcept
Swap this tree with other in O(1).
T get(const size_t i) const
Retrieve the logical value a[i].
T prefix(const size_t i) const
Prefix query: sum of a[0..i].
constexpr size_t size() const noexcept
Number of logical elements.
T query(const size_t l, const size_t r) const
Range query: sum of a[l..r].
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Fenwick tree for arithmetic types with find_kth support.
constexpr unsigned operator()(unsigned a, unsigned b) const noexcept
Fenwick tree (Binary Indexed Tree) for prefix queries.