-
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.
Add the infrastructure to change the segment tree's query function
- Loading branch information
1 parent
c4cebdd
commit 9fc2dbf
Showing
6 changed files
with
87 additions
and
20 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,42 @@ | ||
import math | ||
|
||
from src.preload.function import Function | ||
|
||
_lcm = lambda x, y: x * y / math.gcd(x, y) | ||
|
||
min_f = Function("min_f", min, -1) | ||
max_f = Function("max_f", max, -1) | ||
|
||
add_f = Function("add_f", lambda x, y: x + y, -1) | ||
sub_f = Function("sub_f", lambda x, y: x - y, -1) | ||
mul_f = Function("mul_f", lambda x, y: x * y, -1) | ||
exp_f = Function("exp_f", lambda x, y: x ** y, -1) | ||
mod_f = Function("mod_f", lambda x, y: x % y, -1) | ||
|
||
and_f = Function("and_f", lambda x, y: x & y, -1) | ||
or_f = Function("or_f", lambda x, y: x | y, -1) | ||
xor_f = Function("xor_f", lambda x, y: x ^ y, -1) | ||
|
||
lcm_f = Function("lcm_f", _lcm, -1) | ||
gcd_f = Function("gcd_f", math.gcd, 1) | ||
|
||
avg_f = Function("avg_f", lambda x, y: int((x+y)/2), 0) | ||
|
||
exported_functions: list[Function] = [ | ||
min_f, | ||
max_f, | ||
|
||
add_f, | ||
sub_f, | ||
mul_f, | ||
exp_f, | ||
mod_f, | ||
|
||
and_f, | ||
or_f, | ||
xor_f, | ||
|
||
lcm_f, | ||
gcd_f, | ||
avg_f, | ||
] |
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,9 @@ | ||
from typing import Callable | ||
|
||
class Function: | ||
__slots__ = ("name", "fn", "invalid_query_val") | ||
|
||
def __init__(self, name: str, fn: Callable[[int, int], int], invalid_query_val: int): | ||
self.name = name | ||
self.fn = fn | ||
self.invalid_query_val = invalid_query_val |
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