Under construction

Still being built. Things may change

Tree Beauty

Time limit2sMemory limit512 MB

Summary
Given a rooted tree, apply updates that add floor(Y/K^depth) to a subtree and answer subtree sum queries. N and Q are up to 100,000.
Level

Hard9 of 10

Topics
Tree, Segment tree, Divide and conquer, Math
Solved
No attempts yet

Problem

A rooted tree has N vertices numbered from 1 to N. Vertex 1 is the root, and PiP_i is the parent of vertex ii for all 2≤i≤N2 \le i \le N. Each vertex has a beautiness value, which starts at 0.

A special machine increases the beautiness values of vertices. When you give the machine three parameters X, Y, and K, it increases the beautiness value of every vertex in the subtree of vertex X. If vertex X′X' is in the subtree of vertex X, its beautiness value increases by ⌊Y/Kd⌋\lfloor Y/K^d \rfloor, where d is the number of edges on the path from X to X′X'. For example, vertex X increases by Y, the children of X increase by ⌊Y/K⌋\lfloor Y/K \rfloor, the children of those children increase by ⌊Y/K2⌋\lfloor Y/K^2 \rfloor, and so on.

You perform Q operations one at a time. Each operation is one of the following two types.

  1. Use the machine with parameters X, Y, and K.
  2. Report the total beautiness value of all vertices in the subtree of vertex X.

Input

The first line contains two integers N and Q (1≤N,Q≤100 0001 \le N, Q \le 100\,000), the number of vertices and the number of operations. The next line contains N - 1 integers PiP_i (1≤Pi<i1 \le P_i < i), the parent of each vertex i∈[2,N]i \in [2, N]. Each of the next Q lines is one of the following.

  • 1 X Y K (1≤X≤N1 \le X \le N; 1≤Y,K≤100 0001 \le Y, K \le 100\,000): use the machine with parameters X, Y, and K.
  • 2 X (1≤X≤N1 \le X \le N): report the total beautiness value of the subtree of vertex X.

Output

For each operation of the second type, in the order given in the input, output on its own line the total beautiness value of all vertices in the subtree of vertex X.

Examples1

  1. Example 1

    Input
    5 5
    1 1 3 3
    1 1 99 2
    2 1
    2 3
    1 3 2 3
    2 3
    
    Expected output
    245
    97
    99