CSES Prefix Sum Question Confusion

I have recently tried a problem relating to prefix sums, but I do not know how to solve it. Reading the solution has just left me more confused. I understand everything up to the last paragraph, where I don’t get the math. The implementation also seems strange. Can anyone help?

This probably won’t help, but here’s my (hopefully more readable) solution.