-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jparisu <[email protected]>
- Loading branch information
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Bucles [C++] | ||
|
||
```{contents} | ||
:local: | ||
:depth: 2 | ||
``` | ||
|
||
|
||
```cpp | ||
#include <iostream> | ||
#include <vector> | ||
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<int> tree; | ||
int n; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Bucles [Python] | ||
|
||
```{contents} | ||
:local: | ||
:depth: 2 | ||
``` | ||
|
||
```{todo} | ||
`Work In Progress` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |