QOJ.ac

QOJ

Time Limit: 7 s Memory Limit: 1024 MB Total points: 100

#9648. 数据结构

统计

题目描述

给定一棵 $n$ 个节点的树,钦定点 $1$ 为根,每条边的边权均为 $1$ ,节点 $x$ 有点权 $a_x$ ,初始所有节点的点权均为 $0$ 。总共有 $m$ 次操作,每次操作先给出操作类型 $\text{opt}$ ,接下来给出该操作的所有参数。

  1. 给定一条路径 $(x, y)$ 和范围 $k$ 以及权值 $u$,对于所有点 $i$,当点 $i$ 满足其到树上路径 $(x, y)$ 的最短距离 $\le k$ 时,有 $a_i \gets a_i + u$。
  2. 给定点 $x$ 以及权值 $u$,对于所有点 $x$ 子树内的节点 $i$,有 $a_i \gets a_i + u$。
  3. 给定一条路径 $(x, y)$ 和范围 $k$,对于所有点 $i$,当点 $i$ 满足其到树上路径 $(x, y)$ 的最短距离 $\le k$ 时,询问所有这样的点 $i$ 的点权和。
  4. 给定点 $x$,对于所有点 $x$ 子树内的节点 $i$,询问所有这样的点 $i$ 的点权和。
  5. 给定一条路径 $(x, y)$ 和范围 $k$,对于所有点 $i$,当点 $i$ 满足其到树上路径 $(x, y)$ 的最短距离 $\le k$ 时,询问所有这样的点 $i$ 的点权最大值。
  6. 给定点 $x$,对于所有点 $x$ 子树内的节点 $i$,询问所有这样的点 $i$ 的点权最大值。

其中编号对应操作类型,操作的所有参数将以上述描述的变量顺序给出。

输入格式

输入的第一行包含两个正整数 $n$ 和 $m$,表示树的大小和操作数量。

接下来的第 $2$ 行到第 $n$ 行每行两个正整数 $u, v$ 表示树的一条边 $(u, v)$。

接下来 $m$ 行,每一行首先输入一个整数 $\text{opt}$,表示操作类型:

  • 若 $\text{opt} = 1$,接下来继续输入 $x, y, k, u$;
  • 若 $\text{opt} = 2$,接下来继续输入 $x, u$;
  • 若 $\text{opt} = 3$,接下来继续输入 $x, y, k$;
  • 若 $\text{opt} = 4$,接下来继续输入 $x$;
  • 若 $\text{opt} = 5$,接下来继续输入 $x, y, k$;
  • 若 $\text{opt} = 6$,接下来继续输入 $x$。

输出格式

输出若干行,对于每一种操作三、操作四、操作五、操作六,输出对应的答案。

数据范围

本题开启子任务评测,子任务之间将会设置合理的依赖关系。

  • 子任务 $1$ 和 子任务 $2$ ($10$ 分 + $10$ 分): 保证 $k = 0$ 。
  • 子任务 $3$ 和 子任务 $4$ ($10$ 分 + $10$ 分): 保证所有涉及路径 $(x, y)$ 的操作满足 $x = y$ 。
  • 子任务 $5$ 和 子任务 $6$ ($10$ 分 + $10$ 分): 保证 $k = 1$ 。
  • 子任务 $7$ 和 子任务 $8$ ($20$ 分 + $20$ 分): 无特殊限制。

上述子任务中所有奇数编号子任务不包含操作五和操作六。

对于所有数据,保证 $1 \le n, m \le 2 \times 10^5$,$0 \le k \le 3$,$-10^5 \le u \le 10^5$。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.