Inflation

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

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 NN different dishes on their menu. The iith dish has price p_ip\_i.

Every day, one of the following events happen:

  • INFLATION x: The integer xx is added to all prices.
  • SET x y: Every dish with price xx gets its price set to yy.

Your task is to process QQ days, and after each day print the sum of all prices p_ip\_i.

입력

The first line contains one integer NN, the number of dishes.

The second line contains NN integers p_1,p_2,,p_Np\_1, p\_2, \ldots, p\_N.

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

The following QQ lines each contain a string ss followed by either one or two integers.

If ss is INFLATION, then one integer xx follows. This means that xx is added to all prices on this day.

If ss is SET, then two integers xx and yy follow. This means that all dishes with price xx get their price set to yy on this day.

출력

Print QQ lines, the sum of all prices p_ip\_i after each day.

제한

  • 1N31051 \leq N \leq 3 \cdot 10^5.
  • 1p_i1061 \leq p\_i \leq 10^6 (for each ii such that 1iN1 \leq i \leq N).
  • 1Q1051 \leq Q \leq 10^5.
  • 1x,y1061 \leq x,y \leq 10^6 for all days.

Note: The answer may not fit in a 3232-bit integer, so be aware of overflows if you are using C++.

힌트

This figure corresponds to the first two days of sample 11. Note that the sum of prices after the first day is 1616, so the first integer in the output is 1616.