Help Needed in CSES Hotel Queries

ques : CSES - Hotel Queries

Of course, you can do this in \mathcal{O}(\log^2N)O(log 2 N) time with a max segment tree and binary searching

Can anyone provide me code of this approach and explain what we are doing with segment tree