European Girls' Olympiad in Informatics: 2023 Day 1 Problem 1
People in southern Sweden are known to eat falafel a lot. The price of falafel is highly volatile, and the best way to analyze the state of the economy is to go to the same falafel place every day and add up all the prices on their menu.
A falafel place has different dishes on their menu. The -th dish has price .
Every day, one of the following events happen:
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 Specification
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 Specification
Print lines, the sum of all prices after each day.
Constraints and Scoring
- .
- (for each ).
- .
- .
Note: The answer may not fit in a 32-bit integer, so be aware of overflows if you are using C++.
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group | Score | Limits |
---|---|---|
1 | 14 | |
2 | 28 | |
3 | 19 | There are only INFLATION events. |
4 | 23 | There are only SET events. |
5 | 16 | No additional constraints. |
Example
This figure corresponds to the first two days of sample 1. Note that the sum of prices after the first day is , so the first integer in the output is .
Sample Input 1
5
2 1 1 2 5
6
INFLATION 1
SET 3 2
SET 5 2
INFLATION 4
SET 6 1
SET 10 1
Sample Output 1
16
14
14
34
14
5
Sample Input 2
3
1 4 1
5
SET 1 1
SET 3 4
INFLATION 2
SET 3 1
SET 6 4
Sample Output 2
6
6
12
8
6
Comments