#P4216. [SCOI2015] 情报传递

    ID: 3138 远端评测题 1500ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015四川线段树各省省选平衡树树链剖分,树剖主席树

[SCOI2015] 情报传递

Description

Knight Company is a huge intelligence organization with a vast intelligence network. There are nn agents in the network. Each agent may have several (possibly none) subordinates. Except for one boss, each of the remaining n1n-1 agents has exactly one supervisor. The company has strict discipline: each agent may contact only their own supervisor and subordinates. Meanwhile, any two agents can pass intelligence through the network.

Each day, the company assigns exactly one of the following two tasks:

  1. Collect intelligence: designate agent TT to start collecting intelligence.
  2. Transmit intelligence: transmit a piece of intelligence from agent XX to agent YY.

Initially, all agents are in a dormant stage and are relatively safe; we consider their danger values to be 00. Once an agent starts collecting intelligence, their danger value keeps increasing by 11 per day (on the starting day, the danger value is still 00; on the 2nd day it is 11; on the 3rd day it is 22; and so on). Transmission tasks do not increase any agent’s danger value.

To ensure safety during transmission, each piece of intelligence has a risk control value CC. Among all agents who participate in transmitting this piece (i.e., those on the unique path between XX and YY, inclusive), any agent whose danger value is greater than CC is considered a threat to this piece.

For every transmission task, determine how many agents participate in the transmission and how many of them constitute a threat to this piece.

Input Format

  • The first line contains a positive integer nn, the number of agents.
  • The second line contains nn non-negative integers. The ii-th integer PiP_i denotes the supervisor of agent ii. In particular, if Pi=0P_i = 0, agent ii is the boss.
  • The third line contains a positive integer qq, the number of tasks (one per day).
  • The next qq lines each describe a task. Each line starts with a positive integer kk:
    • If k=1k = 1, it is a transmission task, followed by three positive integers XiX_i, YiY_i, CiC_i, denoting the start, the end, and the risk control value, respectively.
    • If k=2k = 2, it is a collection task, followed by one positive integer TiT_i, the agent who starts collecting intelligence.

Output Format

For each transmission task, output one line containing two integers: the number of participating agents and the number of agents who constitute a threat to this piece of intelligence.

7
0 1 1 2 2 3 3 
6
1 4 7 0
2 1
2 4
2 7
1 4 7 1
1 4 7 3
5 0
5 2
5 1

Hint

Sample explanation:

For the 33 transmission tasks, each passes through 55 agents, namely 44, 22, 11, 33, and 77.

  • In the 1st task, all agents (danger value 00) do not constitute a threat.
  • In the 2nd task, there are 22 threatening agents: agent 11 (danger value 33) and agent 44 (danger value 22). Agent 77 (danger value 11) is not a threat.
  • In the 3rd task, only 11 agent is a threat.

Constraints:

n2×105n \le 2 \times 10^5, q2×105q \le 2 \times 10^5, 0Pi,Cin0 \le P_i, C_i \le n, 1Ti,Xi,Yin1 \le T_i, X_i, Y_i \le n.

Translated by ChatGPT 5