#K10021. Traffic Density Update

    ID: 23154 Type: Default 1000ms 256MiB

Traffic Density Update

Traffic Density Update

You are given n intersections with initial traffic densities given as an array of integers. Then, m events occur that affect the traffic density at a specified intersection. Each event is described by a string, which can be one of the two forms:

  • entry i x: Increase the traffic density at intersection i by x.
  • departure i x: Decrease the traffic density at intersection i by x.

Note that the intersections are 1-indexed. In mathematical terms, if we denote the traffic density at the ith intersection as \(T_i\), then for an event "entry i x" or "departure i x" the update rule is:

[ T_i = \begin{cases} T_i + x, & \text{if the event is } \texttt{entry} \ T_i - x, & \text{if the event is } \texttt{departure} \end{cases} ]

Your task is to compute the final states of all intersections after all events have been processed.

inputFormat

The input is read from stdin and consists of the following:

  1. An integer n denoting the number of intersections.
  2. A line with n space-separated integers representing the initial traffic densities at each intersection.
  3. An integer m denoting the number of events.
  4. m lines, each containing an event in one of the following forms: entry i x or departure i x, where i is the 1-indexed intersection number and x is an integer value.

outputFormat

Output a single line to stdout with n space-separated integers representing the final traffic densities at each intersection after processing all events.

## sample
4
10 20 30 40
5
entry 1 10
departure 2 5
entry 3 15
departure 4 20
entry 1 5
25 15 45 20