House Prices Going Up
InterviewTime limit1sMemory limit1024 MB
Given house prices, process updates that raise one house's price and queries that return the total price of houses l through r.
- Level
Easy3 of 10
- Topics
- Array, Prefix sum
- Solved
- No attempts yet
Problem
The house prices in Virtual County (VC) keep going up. The Virtual County Tax Collection Agency needs help tracking the prices.
The houses in VC are numbered 1 through n, that is, 1, 2, 3, ..., n. VC records each price increase and wants the total price for any section of the county, for example the total for houses 4 through 15.
Input
The first line contains an integer n (), the number of houses. Each of the next n lines contains an integer between 1 and , inclusive, the initial price of one house. The first integer is the price of house 1, the second is the price of house 2, and so on.
The next line contains an integer t (), the number of transactions. Each of the next t lines is one of the following:
- Update: a line starting with U, then a house number i, then an integer x (between 1 and , inclusive). Increase the price of house i by x.
- Retrieve: a line starting with R, then a starting house number l, then an ending house number r. Find the total price of houses l through r. The range is always valid, so r is not less than l.
Output
No output is required for Update transactions. For each Retrieve transaction, print the total price of the requested range on its own line.