diff --git a/docs/md/intermedio/fenwick/fenwick.md b/docs/md/intermedio/fenwick/fenwick.md new file mode 100644 index 0000000..521210d --- /dev/null +++ b/docs/md/intermedio/fenwick/fenwick.md @@ -0,0 +1,24 @@ +# Fenwick Tree + +```{todo} +`Work In Progress` +``` + + +## Lenguajes + +```{toctree} +:maxdepth: 1 + +fenwick_cpp +fenwick_py +``` + + +## Ejercicios + +| Name | Description | Level | URL | +|---------------|------------------|-------|------------------------------------------------| +| fenwick | Update & query | 4.0 | https://open.kattis.com/problems/fenwick | +| supercomputer | Bitsum & biquery | 2.7 | https://open.kattis.com/problems/supercomputer | +| downtime | | 3.1 | https://open.kattis.com/problems/downtime | diff --git a/docs/md/intermedio/fenwick/fenwick_cpp.md b/docs/md/intermedio/fenwick/fenwick_cpp.md new file mode 100644 index 0000000..df00f4c --- /dev/null +++ b/docs/md/intermedio/fenwick/fenwick_cpp.md @@ -0,0 +1,65 @@ +# Bucles [C++] + +```{contents} +:local: +:depth: 2 +``` + + +```cpp +#include +#include +using namespace std; + +struct FenwickTree { + + // O(N) + // Create a Fenwick tree with n elements, all initialized to zero + FenwickTree(int size) + : n(size) + , tree(size) + {} + + // O(logN) + // Add value to the element at index (index starts on 0) + void update(int index, int value) { + index++; + while (index <= n) { + tree[index - 1] += value; + index += index & -index; + } + } + + // O(logN) + // Return the sum from 0 to index (no included) (index starts on 0) + int query(int index) { + int acc = 0; + while (index > 0) { + acc += tree[index - 1]; + index -= index & -index; + } + return acc; + } + + // O(logN) + // Return the sum from 0 to index (included) (index starts on 0) + int query_includes(int index) { + int acc = 0; + index++; + while (index > 0) { + acc += tree[index - 1]; + index -= index & -index; + } + return acc; + } + + // O(logN) + // Return the sum from a to b (both included) + int biquery(int a, int b) { + return query_includes(b) - query(a); + } + + vector tree; + int n; +}; +``` diff --git a/docs/md/intermedio/fenwick/fenwick_py.md b/docs/md/intermedio/fenwick/fenwick_py.md new file mode 100644 index 0000000..5fcb988 --- /dev/null +++ b/docs/md/intermedio/fenwick/fenwick_py.md @@ -0,0 +1,10 @@ +# Bucles [Python] + +```{contents} +:local: +:depth: 2 +``` + +```{todo} +`Work In Progress` +``` diff --git a/docs/md/intermedio/intermedio.md b/docs/md/intermedio/intermedio.md index 9416428..f7985eb 100644 --- a/docs/md/intermedio/intermedio.md +++ b/docs/md/intermedio/intermedio.md @@ -1,6 +1,13 @@ # Nivel intermedio -```{todo} -`Work In Progress` +**1º de programación**. +Este nivel enseña los conceptos básicos de programación y de Programación competitiva. + +```{toctree} +:maxdepth: 1 +:caption: Temario + +entrada_salida/entrada_salida +bucles/bucles ```