Jonathan Sumabat 4

View as PDF

Submit solution

Points: 7
Time limit: 2.5s
Memory limit: 64M

Author:
Problem type

Jonathan Sumabat is a valued member of his school's tech crew. He has been tasked with managing the audio for the next school assembly. This would normally be fine as Jonathan Sumabat is excellent with technology, however his school's soundboard is broken. The soundboard has knobs that Jonathan Sumabat must turn in order to get the perfect sound. Each knob has a specific value and when each are turned to the correct value the sound that Jonathan Sumabat wants is produced. However, for his school's soundboard when one knob is turned it may also change the value of another knob. Jonathan Sumabat is unaware of this and when the assembly comes around he produces a screeching and unbearable sound. Given information about the soundboard and the knobs Jonathan Sumabat turned, determine the values of each knob that produced this horrible sound.

Input Specification

The first line of input is an integer n (1 \le n \le 10^5) representing the number of knobs on the soundboard. They are numbered 1 to n. Initially, each knob has the value of 0.
The next line is k (0 \le k \le n) representing the number of knobs that unintentionally change the value of another knob.
The next k lines contain 4 space separated values representing what happens when each broken knob is turned:

  • The first integer, k_{1} (1 \le k_{1} \le n) is the number of the knob that is broken.
  • The second integer, k_{2} (1 \le k_{2} \le n) is the number of the knob that is affected when the broken knob is turned.
  • The third value, k_{3}, is either the character + or the character * representing the operation that is applied to k_{2} when k_{1} is turned.
  • The last value is an integer k_{4} representing by how much k_{2} is affected.
    (1 \le k_4 \le 100) if k_3 is +, otherwise (1 \le k_4 \le 10).

When k_{1} is turned, the value of k_{2} is increased by k_{4} if k_3 is +. Otherwise, the value of k_2 is multiplied by k_4.
There will never be a set of knobs that change the values of each other infinitely.
The next line is q (1 \le q \le 10^5) representing the number of times Jonathan Sumabat turns a knob. It is possible that he will turn the same knob multiple times.
The next q lines each have two space separated integers:

  • The first, q_1 (1 \le q_1 \le n) represents the knob Jonathan Sumabat turns.
  • The next, q_2 (q \le q_2 \le 100) represents the amount that Jonathan Sumabat increases the knob by.
    At any given point, the value of each knob will fit in a 64 bit signed integer.

Output Specification

On a single line, with each value separated by a space, print the value of each knob on the soundboard in ascending order from 1 to n.

Sample Input

10
5
4 8 + 2
3 2 * 3
8 2 + 23
2 5 + 1
5 1 * 6
3
4 12
8 2
3 9

Sample Output

0 138 9 12 3 0 0 4 0 0

Comments


  • 0
    Serog1sPerog1s  commented on March 28, 2020, 3:52 p.m. edited

    When a knob is turned and affects a knob k2, does this knob k2 in turn affect other knobs? Going by the sample input/output, it seems that ex.turning knob 4 affects knob 8, which affects knob 2 (which affects knob 5).

    Edit: this is definitely the case, now I go be depressed