Array Restoration getting WA even after using sparse table

I am trying to solve Array Restoration on codeforces for such a long time and I am getting WA on 6th test. I used sparse table for finding the minimum of the range in O(1) and it took O(nlogn) for preprocessing the sparse table. I don’t know why I am getting WA at it. Please anyone help me…

Question Link

Submission link

This is my 10th submission by the way…