Inflation
InterviewTime limit3sMemory limit1024 MB
Given N dish prices, apply Q events (add x to every price, or set each price equal to x to y) and print the price sum after each event.
- Level
Medium5 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
People in southern Sweden are known to eat falafel a lot. The price of falafel changes often, and the best way to analyze the state of the economy is to visit the same falafel place every day and add up all the prices on its menu.
A falafel place has different dishes on its menu. The th dish has price .
Every day, one of the following events happens:
INFLATION x: The integer is added to all prices.SET x y: Every dish with price gets its price set to .
Your task is to process days, and after each day print the sum of all prices .
Input
The first line contains one integer , the number of dishes.
The second line contains integers .
The third line contains one integer , the number of days.
The following lines each contain a string followed by either one or two integers.
If is INFLATION, then one integer follows. This means that is added to all prices on this day.
If is SET, then two integers and follow. This means that all dishes with price get their price set to on this day.
Output
Print lines. Line contains the sum of all prices after day .
Constraints
- .
- for each such that .
- .
- for all days.
Note: The answer may not fit in a -bit integer, so be careful about overflow if you use C++.
Hint
This figure corresponds to the first two days of sample . The sum of prices after the first day is , so the first integer in the output is .
