Can someone give me a more detailed explanation of technique used in the solution to problem D ? Or maybe post a link where it is explained in more detail.

The exact problem is here

and also tried to understand the problem given in this editorial

but not able to understand. Can anyone help me to understand the solution of this problem.

@vijju123 can you help us out here.
If possible please explain C,E as well.