#P9463. Salad Sandwich Menu Price Analysis

    ID: 22614 Type: Default 1000ms 256MiB

Salad Sandwich Menu Price Analysis

Salad Sandwich Menu Price Analysis

In this problem, you are given a menu with (N) different items where the price of the (i)-th item is (p_i). Over (Q) days, one of the following events occurs each day:

  • INFLATION x: Increase the price of every item by \(x\).
  • SET x y: For every item currently priced at \(x\), change its price to \(y\).

After processing the event of each day, output the sum of the prices of all items. Note that if an event updates an item’s price, it may affect future operations.

inputFormat

The first line contains two integers (N) and (Q) -- the number of items and the number of days. The second line contains (N) integers (p_1, p_2, \ldots, p_N) representing the initial prices of the menu items.

Each of the next (Q) lines contains one of the following commands:

  • INFLATION x: Increase every price by \(x\).
  • SET x y: Change every item that has a price equal to \(x\) to price \(y\).

outputFormat

Output (Q) lines, where the (i)-th line contains the total sum of the prices of all items after processing the (i)-th day's event.

sample

3 3
10 20 30
INFLATION 5
SET 15 25
INFLATION 10
75

85 115

</p>