Max query Problem

In this question can’t we build tree for every query?

I mean for every value of k, we create a segment tree that checks specifically for that particular k

building tree be O(n)
if you build for each query then,
in this question u will get TLE

@aiman.mumtaz have you re-opened this doubt?