I need to implement data structure that can answer for O(logn) to these queries:
Given sequence f(n), f(-2) = f(-1) = 1, f(n) = (a(n) * f(n-1) + b(n) * f(n-2)) mod M
, queries:
- replace pair
(a(i), b(i))
with(a, b)
; - evaluate
f(i)
for giveni
.
I was thinking about Fenwick tree and fast matrix multiplication for finding i-th
element of reccurent sequence, but I’m not sure if it’s a good approach.
New contributor
sdfg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.