#P7746. Factory Salary Monitoring

    ID: 20933 Type: Default 1000ms 256MiB

Factory Salary Monitoring

Factory Salary Monitoring

A factory has \(n\) employees. Each employee (except Mirko) has exactly one boss. Mirko is employee \(1\) and is considered to be the boss of everyone, while the remaining employees are numbered from \(2\) to \(n\). Each employee can adjust the salary of all of his subordinates (both direct and indirect) by a certain amount (which can be positive or negative). In order to prevent abuse of power, Mirko occasionally wants to know the salary of a particular employee. Your task is to process a series of commands and monitor the salary changes accordingly.

Note: At any moment, all salaries remain positive integers and fit in a standard 32-bit integer type.

The commands are given in the input as described below.

inputFormat

The input begins with two integers \(n\) and \(m\) (the number of employees and the number of commands, respectively).

The second line contains \(n\) integers, representing the initial salaries of employees \(1\) through \(n\). (Employee \(1\) is Mirko.)

The third line contains \(n-1\) integers. The \(i\)th integer (for \(i=1\) to \(n-1\)) represents the boss of employee \(i+1\).

The following \(m\) lines each contain a command. Each command is in one of the following two formats:

  • p e s — Employee \(e\) adjusts the salary of all of his subordinates (i.e. all employees in his subtree, excluding himself) by adding the integer \(s\) (\(s\) can be negative or positive).
  • u e — Query the current salary of employee \(e\).

It is guaranteed that after any update, all salaries remain positive.

outputFormat

For each query command (of the form u e), output the current salary of employee \(e\) on a new line.

sample

5 5
100 90 80 70 60
1 1 2 3
p 1 10
u 4
p 2 -5
u 4
u 5
80

75 70

</p>