#P3920. [WC2014] 紫荆花之恋

    ID: 2863 远端评测题 12000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2014点分治平衡树WC/CTSC/集训队O2优化分治

[WC2014] 紫荆花之恋

Description

Qiangqiang and Mengmeng are good friends. One day while strolling outside, they suddenly saw a bauhinia tree ahead. It was the season when bauhinia blossoms flutter, and countless petals were growing from the tree at a speed visible to the naked eye.

Looking closely, this big tree is actually a weighted tree. At each moment it grows a new leaf node. There is a cute little spirit on every node, and a new spirit also appears on each newly grown node. Spirits are adorable but fragile creatures. Each spirit ii has a sensitivity value rir_i. Spirits ii and jj become friends if and only if their distance on the tree satisfies dist(i,j)ri+rj\operatorname{dist}(i,j) \leq r_i + r_j, where dist(i,j)\operatorname{dist}(i,j) denotes the sum of edge weights along the unique path from ii to jj on this tree.

Qiangqiang and Mengmeng are curious: after each new leaf node appears, how many pairs of friends are there in total on the tree?

We assume the tree is initially empty, and nodes are numbered from 11 in the order they are added. Since Qiangqiang is very curious, you must output the total number of friend pairs immediately after each new node appears, without delay.

Input Format

The first line contains an integer representing the test point ID.

The second line contains a positive integer nn, the total number of nodes to be added.

Let last_anslast\_ans be the total number of friend pairs before adding the current node, with initial value 00.

In each of the next nn lines, the ii-th line contains three non-negative integers ai,ci,ria_i, c_i, r_i, meaning that the parent ID of node ii is ai(last_ansmod109)a_i \oplus (last\_ans \bmod 10^9) (where \oplus denotes XOR; the data guarantees that the result after this operation lies between 11 and i1i-1 inclusive), the edge weight to its parent is cic_i, and the sensitivity of the spirit on node ii is rir_i.

Note that a1=c1=0a_1 = c_1 = 0, meaning node 11 is the root. For i>1i > 1, the parent ID is at least 11.

Output Format

Output nn lines. The ii-th line contains one integer: the number of pairs of friends in the tree after adding node ii.

0
5
0 0 6
1 2 4
0 9 4
0 5 5
0 2 4

0
1
2
4
7

Hint

All data satisfy 1ci1041 \leq c_i \leq 10^4, ai2×109a_i \leq 2 \times 10^9, and ri109r_i \leq 10^9.

Test point ID Assumption
1,21,2 n100n \leq 100
3,43,4 n1000n \leq 1000
5,6,7,85,6,7,8 n105n \leq 10^5, node 11 has at most two children, other nodes have at most one child
9,109,10 n105n \leq 10^5, ri10r_i \leq 10
11,1211,12 n105n \leq 10^5, the tree is generated randomly
13,14,1513,14,15 n7×104n \leq 7 \times 10^4
16,17,18,19,2016,17,18,19,20 n105n \leq 10^5

Translated by ChatGPT 5