Under construction

Still being built. Things may change

Salary Management at a Car Factory

Time limit1sMemory limit256 MB

Summary
Given a company tree with salary updates that add a value to all subordinates of a node and queries for a single employee's current salary, answer efficiently using an Euler tour and a range-update point-query structure.
Level

Medium6 of 10

Topics
Tree, Prefix sum, DFS
Solved
No attempts yet

Problem

Sanggeun works at a car factory and, after several promotions, has become its president. The factory has N employees in total. Sanggeun is employee 1; the other employees are numbered from 2 to N. Every employee except Sanggeun has exactly one direct manager.

Each employee can increase or decrease the salaries of all of their subordinates at once. A subordinate means any employee below them in the organization tree, including indirect subordinates, but not the employee themselves.

Given salary-change commands and salary-query commands, write a program that prints the current salary of the requested employee for each query.

Every employee's salary is always a positive integer and at most 2^31 - 1.

Input

The first line contains the number of employees N and the number of commands M. (1 <= N, M <= 500,000)

The next N lines describe the employees. The i-th of these lines describes employee i. Employee 1 has no manager, so only their initial salary is given. For employees 2 through N, the initial salary and the direct manager's number are given.

Each of the next M lines contains one of the following commands.

  1. p a x: Increase the salary of every subordinate of employee a by x. (-10,000 <= x <= 10,000)
  2. u a: Print the current salary of employee a.

Output

For every u command, print the current salary of the requested employee on its own line.

Examples3

  1. Example 1

    Input
    2 3
    5
    3 1
    p 1 5
    u 2
    u 1
    
    Expected output
    8
    5
    
  2. Example 2

    Input
    5 5
    4
    2 1
    6 1
    7 1
    3 4
    u 3
    p 1 -1
    u 3
    p 4 5
    u 5
    
    Expected output
    6
    5
    7
    
  3. Example 3

    Input
    6 7
    5
    4 1
    3 2
    7 3
    2 3
    3 5
    p 3 2
    p 2 4
    u 3
    u 6
    p 5 -2
    u 6
    u 1
    
    Expected output
    7
    9
    7
    5