Max Query 1 in segment trees showing tle.

I am making a segment tree which stores min and max values of the corresponding range at each node.If k>max value return 0; or if k<min return length of range. if min<k<max.Then recursively check the nodes below but my time limit is getting exceeded.Is my approach correct complexity-wise.?

looks like your query is taking O( logn) complexity per query.
Now the final required complexity depends on the constraint of question whether your logic will work or not.

  1. Mention problem name
  2. Link to problem
  3. Paste code on coding blocks ide and share the link here