### Khalell's blog

By Khalell, history, 7 weeks ago,

i have a problem as follow Given a tree with n nodes with unique value for each node and q queries as given two nodes a and b ,find Mex in the path from a to b for each query

(1<n,q<200000)

my solution is using Mo algorithm as mentioned Here. i can find the Mex either using segment tree or set with log(n) for each query,but i think it is a bit hard for my solution to be valid under this constraints .

is there another solution with a better time complexity ?

• +7

 » 7 weeks ago, # |   0 Auto comment: topic has been updated by Khalell (previous revision, new revision, compare).
 » 7 weeks ago, # |   +1 Because of unique value for each node, I think you can for each k find the shotest path p[k] such that 0...k is all on the path p[k]. Then binary search for each query. Can be done with O((n+q) log n).
•  » » 7 weeks ago, # ^ |   0 it is a great idea ,thanks a lot
 » 7 weeks ago, # |   0 https://codeforces.com/blog/entry/100910I hope this will help you a bit!
•  » » 7 weeks ago, # ^ |   0 it will,thanks
 » 4 weeks ago, # | ← Rev. 2 →   +10 Have a look at CF 1930 HThe solution($O(n \cdot \log(n))$) to 1930 H would work even if you had updates in your problem.