Chef Under Pressure - CHEFPRES TLE

can you please tell me why LCA by RMQ giving TLE , and lca by naive approach is AC .i think logarithmic time must AC then leaner O(N) for every query.

LCA by RMQ : my source-rmq-TLE

LCA by naive : my source-naive-AC