#P9463. [EGOI 2023] Inflation / 通货膨胀

[EGOI 2023] Inflation / 通货膨胀

Background

Day 1 Problem A.

The statement is translated from EGOI2023 inflation.

CC BY-SA 3.0

Problem Description

As everyone knows, people in southern Sweden often eat salad sandwiches. The prices of salad sandwiches change a lot, and the best way to analyze the economy is to go to the same salad sandwich shop every day and add up all prices on the menu.

A salad sandwich shop has NN different items on its menu. The ii-th item has price pip_i.

Each day, one of the following events happens:

  • INFLATION x: All prices increase by xx.
  • SET x y: The price of every item whose price is xx is changed to yy.

Your task is to process QQ days, and after the end of each day, output the total price of all items.

Input Format

The first line contains an integer NN, the number of items.

The second line contains NN integers p1,p2,,pNp_1,p_2,\cdots,p_N.

The third line contains an integer QQ, the number of days.

The next QQ lines each contain a string ss and one or two integers.

If ss is INFLATION, then it is followed by one integer xx, meaning that all prices increase by xx on that day.

If ss is SET, then it is followed by two integers x,yx,y, meaning that the price of every item whose price is xx is changed to yy.

Output Format

Output QQ lines. Each line should contain the total price of all items after the end of that day.

5
2 1 1 2 5
6
INFLATION 1
SET 3 2
SET 5 2
INFLATION 4
SET 6 1
SET 10 1
16
14
14
34
14
5
3
1 4 1
5
SET 1 1
SET 3 4
INFLATION 2
SET 3 1
SET 6 4
6
6
12
8
6

Hint

Sample 11 Explanation

The figure below shows the first two days of sample 11. Note that after the end of day 1, the total sum of prices is 1616, so the first output integer is 1616.


Constraints

For all testdata, 1N3×1051\le N\le 3\times 10^5, 1pi1061\le p_i\le 10^6, 1Q1051\le Q\le 10^5, 1x,y1061\le x,y\le 10^6.

  • Subtask 1 (1414 points): N=1N=1.
  • Subtask 2 (2828 points): N,Q,pi,x,y100N,Q,p_i,x,y\le 100, depends on Subtask 1.
  • Subtask 3 (1919 points): Only INFLATION events.
  • Subtask 4 (2323 points): Only SET events.
  • Subtask 5 (1616 points): No special constraints, depends on Subtasks 2, 3, and 4.

Hint

The answer may not fit in a 32-bit integer. If you use C++, be careful about possible overflow.

Translated by ChatGPT 5