QOJ.ac

QOJ

時間限制: 7 s 記憶體限制: 1024 MB 總分: 100

#9648. Data Structures

统计

Given a tree with $n$ nodes, let node $1$ be the root. Each edge has a weight of $1$. Each node $x$ has a weight $a_x$, initially $0$ for all nodes. There are $m$ operations. Each operation starts with an operation type $\text{opt}$, followed by its parameters:

  1. Given a path $(x, y)$, a range $k$, and a value $u$: for all nodes $i$ such that the shortest distance from $i$ to the path $(x, y)$ is $\le k$, update $a_i \gets a_i + u$.
  2. Given a node $x$ and a value $u$: for all nodes $i$ in the subtree of $x$, update $a_i \gets a_i + u$.
  3. Given a path $(x, y)$ and a range $k$: for all nodes $i$ such that the shortest distance from $i$ to the path $(x, y)$ is $\le k$, query the sum of weights $a_i$ for all such nodes $i$.
  4. Given a node $x$: for all nodes $i$ in the subtree of $x$, query the sum of weights $a_i$ for all such nodes $i$.
  5. Given a path $(x, y)$ and a range $k$: for all nodes $i$ such that the shortest distance from $i$ to the path $(x, y)$ is $\le k$, query the maximum weight $a_i$ among all such nodes $i$.
  6. Given a node $x$: for all nodes $i$ in the subtree of $x$, query the maximum weight $a_i$ among all such nodes $i$.

The operation numbers correspond to the types above, and the parameters are provided in the order described.

Input

The first line contains two positive integers $n$ and $m$, representing the size of the tree and the number of operations.

The next $n-1$ lines each contain two positive integers $u, v$, representing an edge $(u, v)$ in the tree.

The next $m$ lines each start with an integer $\text{opt}$, representing the operation type:

  • If $\text{opt} = 1$, then $x, y, k, u$ follow.
  • If $\text{opt} = 2$, then $x, u$ follow.
  • If $\text{opt} = 3$, then $x, y, k$ follow.
  • If $\text{opt} = 4$, then $x$ follows.
  • If $\text{opt} = 5$, then $x, y, k$ follow.
  • If $\text{opt} = 6$, then $x$ follows.

Output

Output several lines, providing the answer for each operation of type 3, 4, 5, or 6.

Constraints

This problem uses subtask evaluation, with dependencies between subtasks.

  • Subtasks 1 and 2 (10 points + 10 points): $k = 0$ is guaranteed.
  • Subtasks 3 and 4 (10 points + 10 points): All operations involving a path $(x, y)$ satisfy $x = y$.
  • Subtasks 5 and 6 (10 points + 10 points): $k = 1$ is guaranteed.
  • Subtasks 7 and 8 (20 points + 20 points): No special restrictions.

All odd-numbered subtasks do not include operations 5 and 6.

For all data, $1 \le n, m \le 2 \times 10^5$, $0 \le k \le 3$, and $-10^5 \le u \le 10^5$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.