ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2180. Need More Tasks

Time limit: 2.0 second
Memory limit: 256 MB
In one country, there is a government consisting of N deputies in a certain hierarchy. At the top is the Prime Minister, who has no immediate superiors and is numbered 1, while each other deputy has exactly one immediate superior.
Unfortunately for them, the next Q days will be very difficult — the president of the country has decided to test the government for efficiency. On the i-th day, he can perform one of two actions:
  1. Give the vi-th deputy xi impossible tasks with access level ki. If the access level of the task is 0, it cannot be passed on to anyone. Otherwise, the deputy can pass these same tasks to all his immediate subordinates, if any, with access level ki − 1. Since the tasks are impossible, each deputy who receives these tasks either from the president or from an immediate superior will definitely pass them down the hierarchy if the access level allows, but he will also be working on them.
  2. Force the deputy with number vi to report on each of the tasks from the president that he is currently working on.
Initially, deputies have no tasks. The tasks are impossible to complete, but it’s better not to mention this to the president, as he might dissolve the government. You are required to assist the deputies who need to prepare reports. If on the i-th day a request for reports on tasks comes in, inform how many reports this deputy will have to write in total.

Input

The first line contains an integer N — the number of deputies in the government (2 ≤ N ≤ 105).
The second line contains N−1 integers pi — the numbers of the immediate superiors of the deputies numbered from 2 to N (1 ≤ pii − 1).
The third line contains an integer Q — the number of days on which the president will make requests (1 ≤ Q ≤ 105).
The following Q lines describe these requests in the following format:
  • + vi ki xi — on the i-th day, the president gives the deputy with number vi xi impossible tasks with access level ki (1 ≤ viN, 0 ≤ kiN, 1 ≤ xi ≤ 109).
  • ? vi — on the i-th day, the president requests a report on each of the tasks that the deputy with number vi is currently working on (1 ≤ viN).

Output

For each day when the president requests reports, output the number of reports.

Sample

inputoutput
4
1 1 2
6
? 3
+ 1 1 5
? 2
+ 2 1 9
? 4
? 2
0
5
9
14
Problem Author: Vladimir Cherepanov
Problem Source: Ural School Programming Contest 2023