-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
55 lines (46 loc) · 1.81 KB
/
Copy pathmain.py
File metadata and controls
55 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from timeit import default_timer as timer
from Solutions.naive import Naive
from Solutions.polynomial_hash import Polynomial_hash
from Solutions.bit_and_polynomial_hashing import BIT_and_polynomial_hashing
with open("data/data1.txt", "r") as inFile:
N, Q = map(int, inFile.readline().split())
arr = [0] + list(map(int, inFile.readline().split()))
naive_sol = Naive(arr, N)
polynomial_hashing_sol = Polynomial_hash(arr, N)
BIT_hashing_sol = BIT_and_polynomial_hashing(arr, N)
queries = []
for _ in range(Q):
queries.append(list(map(int, inFile.readline().split())))
# polyhash_start = timer()
# for query in queries:
# if query[0] == 1:
# t, l1, r1, l2, r2 = query
# polynomial_hashing_sol.query(l1, r1)
# polynomial_hashing_sol.query(l2, r2)
# if query[0] == 2:
# t, ind, val = query
# polynomial_hashing_sol.update(ind, val)
# polyhash_end = timer()
# print(f"PolyHashing Solution took: {polyhash_end - polyhash_start}")
bit_polyhash_start = timer()
for query in queries:
if query[0] == 1:
t, l1, r1, l2, r2 = query
BIT_hashing_sol.query(l1, r1)
BIT_hashing_sol.query(l2, r2)
if query[0] == 2:
t, ind, val = query
BIT_hashing_sol.update(ind, val)
bit_polyhash_end = timer()
print(f"BIT & Hashing Solution took: {bit_polyhash_end - bit_polyhash_start}")
naive_start = timer()
for query in queries:
if query[0] == 1:
t, l1, r1, l2, r2 = query
naive_sol.query(l1, r1)
naive_sol.query(l2, r2)
if query[0] == 2:
t, ind, val = query
naive_sol.update(ind, val)
naive_end = timer()
print(f"Naive Solution took: {naive_end - naive_start}")