oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

payraise Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

statement.html

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

Tags

Graph Theory, Data Structure, Preorder

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
1100233s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o payraise -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.