Stadium SAPO 2018 solution

So I was doing some problems to try and increase my chances of passing silver when i came across this problem. I read the guide’s solution and but I just don’t understand. Can someone help? Thanks in advance

The last part of the internal solution mentions a previous problem in the guide (Bit Inversions). Did you solve that problem first?

Yes I solved the bit inversion problem and I understand it.

Is there any specific part you don’t understand? I can walk you through the problem if you want

Yes, if you could walk me through the solution that would be nice. I understand it very high level, but I don’t understand the implementation. I kinda get what the gap vector does, but I don’t understand what the purpose of the edges vector is.

edges stores the y-coordinates of the trees in the window you’re currently checking so that when you insert a new tree, you can update gaps efficiently (CSES Bit Inversions also uses this I think). Is there anything else you don’t understand?

Ohh, I think I get it. Just to clarify, the reason the for loop starts at -1 is so we can account for the case where the side of the stadium is the side of the park right?