P9463 [EGOI 2023] Inflation / Inflation

Background

Day 1 Problem A. The statement is translated from [EGOI2023 inflation](https://egoi23.se/assets/tasks/day1/inflation.pdf). [![CC BY-SA 3.0](https://licensebuttons.net/l/by-sa/3.0/80x15.png)](https://creativecommons.org/licenses/by-sa/3.0/)

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 $N$ different items on its menu. The $i$-th item has price $p_i$. Each day, one of the following events happens: - `INFLATION x`: All prices increase by $x$. - `SET x y`: The price of every item whose price is $x$ is changed to $y$. Your task is to process $Q$ days, and after the end of each day, output the total price of all items.

Input Format

The first line contains an integer $N$, the number of items. The second line contains $N$ integers $p_1,p_2,\cdots,p_N$. The third line contains an integer $Q$, the number of days. The next $Q$ lines each contain a string $s$ and one or two integers. If $s$ is `INFLATION`, then it is followed by one integer $x$, meaning that all prices increase by $x$ on that day. If $s$ is `SET`, then it is followed by two integers $x,y$, meaning that the price of every item whose price is $x$ is changed to $y$.

Output Format

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

Explanation/Hint

**Sample $1$ Explanation** The figure below shows the first two days of sample $1$. Note that after the end of day 1, the total sum of prices is $16$, so the first output integer is $16$. ![](https://cdn.luogu.com.cn/upload/image_hosting/jnt1pk1u.png) --- **Constraints** For all testdata, $1\le N\le 3\times 10^5$, $1\le p_i\le 10^6$, $1\le Q\le 10^5$, $1\le x,y\le 10^6$. - Subtask 1 ($14$ points): $N=1$. - Subtask 2 ($28$ points): $N,Q,p_i,x,y\le 100$, depends on Subtask 1. - Subtask 3 ($19$ points): Only `INFLATION` events. - Subtask 4 ($23$ points): Only `SET` events. - Subtask 5 ($16$ 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