The constructor is called once with the tree structure (parent array). This is where you build the table. Compute (around for ). Allocate up[n][log n]. Fill it column by column as before. Time: . This runs only once, so it is fine even if is large.
Each query then reads from the precomputed table. The amortized cost per operation is low because the preprocessing dominates.