Persistence Made Simple - Tutorial

One of the best tutorial I ever saw.
Great work.

Could somebody give me the implimentation of this problem with this code of persistent seg tree please.I don’t know why it gives me wrong answer. This problem

The code