-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfinite_seq.py
More file actions
36 lines (29 loc) · 836 Bytes
/
Copy pathinfinite_seq.py
File metadata and controls
36 lines (29 loc) · 836 Bytes
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
from functools import cache
_seq = []
_dp = {}
def _build_seq(seq, r):
n = len(seq)
if r <= n:
return seq
_count = 0
_counts = [0] * ((r + 1) // 2)
for i in range(n):
if seq[i] == 1:
_count += 1
_counts[i] = _count % 2
return _counts
def _get_value(_counts: list, r: int):
n = len(_counts)
if (r + 1 // 2 - 1) <= n:
return _counts[(r + 1) // 2 - 1]
_count = _get_value(_counts, (r + 1) // 2 - 1)
if _count % 2 == 1:
return _count + 1
else:
return _count
if __name__ == "__main__":
t = int(input().rstrip())
for t_itr in range(t):
(n, l, r) = tuple([int(x) for x in input().rstrip().split()])
a = list([int(x) for x in input().rstrip().split()])
print(_get_value(_build_seq(a, r), r) % 2 == 0)