Calculate the sum

How to find array after q operations And by the value x