Coffee Shop Game 2
InterviewTime limit2sMemory limit256 MB
Given an array, answer Q online queries each asking a range sum (with swapped bounds allowed) followed by a point update.
- Level
Medium4 of 10
- Topics
- Segment tree, Prefix sum, Array
- Solved
- No attempts yet
Problem
A game is played in a coffee shop.
Initially, there are integers arranged in a row. Each turn has two steps.
- Given two positions and , find the sum of the current array from the -th number through the -th number.
- Given a position and a value , replace the -th number with .
Write a program that prints the required range sum for every turn.
Input
The first line contains the number of integers and the number of turns .
The second line contains the initial integers in the array.
Each of the next lines contains four integers , , , and , describing one turn. First find the sum from the -th number through the -th number in the current array, then replace the -th number with .
Every integer in the input is between and , inclusive.
Output
For each turn, output the computed range sum on its own line.
Hint
Normally, means from the -th number through the -th number. In this problem, if , compute the sum from the -th number through the -th number instead.