payraise

Problem Description

A company has N employees, numbered 0 to N-1. The boss of the company is employee 0, while every other employee i has a direct superior Pi. Since employee 0 has no direct superior, P0 = -1. Each employee i starts with an initial salary of Si dollars.

There will be a total of Q operations that you have to handle, each of them being one of two types:

  • A raise operation, where we raise the salaries of employee x and all of their direct and indirect subordinates by d dollars.
  • A query operation, where we want to know the current salary of employee x.

Input

The first line of input will contain two integers, N and Q.

The next line of input will contain N integers, indicating the array P.

The next line of input will contain N integers, indicating the array S.

The next Q lines of input will describe one operation each, in the following formats:

  • 0 x d, indicating a raise operation on employee x (and their subordinates) by d dollars.
  • 1 x, indicating a query operation on employee x.

Output

The output should contain one line with one integer for each query operation, indicating the current salary of the requested employee.

Limits

1 ≤ N, Q ≤ 106.

0 ≤ Pi < i, for all 1 ≤ i < N.

0 ≤ x < N

0 ≤ d, Si ≤ 109.

Sample Input

5 5
-1 0 0 1 1
1 3 2 3 2
0 1 3
1 4
0 0 2
1 1
1 3

Sample Output

5
8
8


Submitting .cpp to 'payraise'


You're not logged in! Click here to login

Time Limit: 3 Seconds
Memory Limit: 256MB
Your best score: 0
Source: Dunjudge Archive
Editorial: 1

Subtask Score
1 100
2 0