#P10603. BZOJ4372 烁烁的游戏

    ID: 12085 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树O2优化树链剖分动态树分治

BZOJ4372 烁烁的游戏

Background

This problem comes from the original BZOJ. We acknowledge that the statement and original testdata are copyrighted by the original BZOJ or the problem author who authorized BZOJ to use it. If you are the copyright holder and believe we have infringed your rights, please contact us.


Shuoshou really likes climbing trees, which scares the Pipishu (pípíshǔ) on the tree.

You are given a tree with nn nodes, where all edge weights are 11. Initially, there are no Pipishu on the tree.

Each time, Shuoshou jumps to a node uu and attracts ww Pipishu to each node whose distance to him is at most dd. Since the Pipishu are attracted by Shuoshou, they will stay at their nodes and never move.

Shuoshou is curious: at the current moment, how many of his good friends—Pipishu—are on node uu.

Problem Description

The background can be abstracted into the following problem:

Given a tree with nn nodes, where all edge weights are 11, and the initial node weights are all 00. Perform mm operations:

  • Q x\text{Q x}: query the node weight of node xx.
  • M x d w\text{M x d w}: add ww to the node weight of every node whose distance to node xx is at most dd.

Input Format

The first line contains two positive integers n,mn, m.

The next n1n - 1 lines each contain two positive integers u,vu, v, indicating that there is an edge between uu and vv.

The next mm lines each describe one of the two operations above.

Output Format

For each QQ operation, output the current node weight of node xx.

7 6
1 2
1 4
1 5
2 3
2 7
5 6
M 1 1 2
Q 5
M 2 2 3
Q 3
M 1 2 1
Q 2
2
3
6

Hint

For all data, it is guaranteed that 1n,m1051 \leq n, m \leq 10^5 and w104|w| \leq 10^4. Note that ww is not necessarily positive.

Translated by ChatGPT 5