How to solve BACREP in October challenge?

We could use LCA if there was no updates in queries .So how to solve that problem for 100 points ?
https://www.codechef.com/OCT19A/problems/BACREP

See e.g. BACREP - Algorithm behind? (and the rest of that thread).