Subarray Replacement

You are one of the greatest programmers of the decade. Ahasan heard that you can solve range query problems in a minute. He came to you with the following problem.


This is a companion discussion topic for the original entry at https://toph.co/p/subarray-replacement