Calculate the sum

How to find array after q operations