Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4de967
commit f03e148
Showing
14 changed files
with
981 additions
and
88 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
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
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,60 @@ | ||
--- | ||
title: Python template for contests | ||
seoTitle: Python template for contests | ||
description: Python template for contests | ||
toc: true | ||
tags: [] | ||
categories: [Algorithms] | ||
series: | ||
date: 2023-02-07 | ||
lastmod: 2023-02-09 | ||
# featuredImage: | ||
draft: false | ||
weight: 10 | ||
--- | ||
|
||
|
||
```python | ||
import math | ||
import os | ||
import sys | ||
import time | ||
from collections import defaultdict, Counter | ||
|
||
|
||
INF = sys.maxsize | ||
|
||
# ------ INPUTS | ||
|
||
inp = lambda: sys.stdin.readline().strip().rstrip("\r\n") #read line as string. Ex: input 1 2 3 => '1 2 3' | ||
inpi = lambda: int(inp()) #read input as integer. input 1 => 1 | ||
inpl = lambda: list(map(int, inp().split())) #read line as list of integers. Ex: [1, 2, 3] | ||
inp_strl = lambda: list(inp().split()) #read line as list of strings. Ex: ['1', '2', '3'] | ||
|
||
list_to_string = lambda _v: "".join(map(str, _v)) # [1,2,3] => '123' | ||
list_to_string_list = lambda _v: " ".join(map(str, _v)) # [1,2,'3'] => '1 2 3' | ||
|
||
|
||
# ------ SOLUTION | ||
|
||
def solve(): | ||
# input | ||
|
||
return | ||
|
||
|
||
def run(): | ||
solve() | ||
print(solve()) | ||
|
||
|
||
if __name__ == "__main__": | ||
LOCAL_TESTS = 0 | ||
if os.environ.get("LOCAL_TESTS") or LOCAL_TESTS: | ||
sys.stdin = open("./input.txt", "r") | ||
start_time = time.time() | ||
run() | ||
print("\n--- %s seconds ---\n" % (time.time() - start_time)) | ||
else: | ||
run() | ||
``` |
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,66 @@ | ||
--- | ||
title: Data Structures | ||
description: null | ||
authors: | ||
categories: ['programming', 'Data Structures', 'Codeforces'] | ||
tags: ['Data Structures'] | ||
# series: null | ||
# featuredImage: null | ||
toc: false | ||
weight: 40 | ||
date: 2023-02-09 | ||
lastmod: 2023-02-09 | ||
published: true | ||
--- | ||
|
||
|
||
### Tree | ||
|
||
```python | ||
class Node: | ||
def __init__(self, value): | ||
self.value = value | ||
self.children = {} | ||
|
||
def insert(self, s, idx): | ||
# idx: index of the current character in s | ||
if idx != len(s): | ||
self.children.setdefault(s[idx], Node(s[idx])) | ||
self.children.get(s[idx]).insert(s, idx + 1) | ||
``` | ||
|
||
### Fenwick Tree | ||
|
||
```python | ||
class Fenwick: #also known as Binary Indexed Tree (BIT) | ||
def __init__(self, n): | ||
self.n = n | ||
self.bit = [0] * (n+1) | ||
def add(self, idx, val): | ||
while idx <= self.n: | ||
self.bit[idx] += val | ||
idx += idx & -idx | ||
def add_range(self, l, r, val): | ||
self.add(l, val) | ||
self.add(r+1, -val) | ||
def point_query(self, idx): | ||
#Calculates the sum of the elements from the beginning to idx | ||
ret = 0 | ||
while idx > 0: | ||
ret += self.bit[idx] | ||
idx -= idx & -idx | ||
return ret | ||
``` | ||
|
||
|
||
- [A Visual Introduction to Fenwick Tree | medium](https://medium.com/carpanese/a-visual-introduction-to-fenwick-tree-89b82cac5b3c) | ||
- [Fenwick Tree](https://cp-algorithms.com/data_structures/fenwick.html) | ||
- [Дерево Фенвика | algorithmica](https://ru.algorithmica.org/cs/range-queries/fenwick/) | ||
- [Дерево Фенвика | habr](https://habr.com/ru/post/112828/) | ||
|
||
|
||
## Resources | ||
|
||
- [data structures](https://github.com/OpenGenus/cosmos) | ||
- [Competitive Programming Library](https://github.com/cheran-senthil/PyRival) | ||
- [Algorithms for Competitive Programming](https://cp-algorithms.com/) |
Binary file added
BIN
+29.6 KB
content/docs/algorithms-101/data-structures/assets/segment-tree-structure.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.6 KB
content/docs/algorithms-101/data-structures/assets/segment-tree-structure.ru.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.2 KB
content/docs/algorithms-101/data-structures/assets/segment-tree-sum.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.2 KB
content/docs/algorithms-101/data-structures/assets/segment-tree-sum.ru.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.