0 0 0 0 0 0
1 0 0 -1 0 0
This is how we update it
Now, one prefix sum will make it
1 1 1 0 0 0
Second will make it
1 2 3 3 3 3
Now can you see how it helps?
We need to remove last 3 3 3 by one more update on initial array
Now try to connect these pieces. The editorial will be out soon. Then you can read full solution if you are not able to figure it out.