QOJ.ac

QOJ

Límite de tiempo: 3.5 s Límite de memoria: 512 MB Puntuación total: 100

#195. 贩运者

Estadísticas

Pablo 是西部最臭名昭著的人之一,他以对 $N$ 座城市的影响力而闻名,这些城市由形成树状结构的道路相互连接。Pablo 的心腹是走私贩,他们不停地运输货物。每个走私贩由一对城市 $(u, v)$ 定义,具体如下:走私贩从时间 $0$ 开始,从城市 $u$ 出发前往城市 $v$,沿最短路径行进。在每个整数时刻,每个走私贩都会运送一个单位的货物,然后移动到下一个城市。

Pablo 的走私贩行踪难以追踪:一旦走私贩到达目的地城市 $v$ 并运送了货物,在下一个时刻,他会传送回城市 $u$(如果在时刻 $t$ 他在城市 $v$ 运送货物,那么在时刻 $t+1$ 他将在城市 $u$ 运送货物)。由于生意兴隆,且停止营业会很可惜,走私贩将永远沿着他们的路线行进。

尽管 Pablo 建立的系统看起来无懈可击,但他想知道是否有改进的空间。因此,他将在系统上执行 3 种类型的查询:

  • 1 u v:添加一个在城市对 $(u, v)$ 之间往返的走私贩。
  • 2 u v:移除一个在城市对 $(u, v)$ 之间往返的走私贩。保证这样的走私贩存在。
  • 3 u v t1 t2:Pablo 想知道在时间 $t_1$ 到 $t_2$(含 $t_1$ 和 $t_2$)之间,所有现有走私贩在城市 $u$ 和 $v$ 之间的最短路径(含端点)上的所有城市中,总共运送了多少单位货物。

输入格式

第一行包含 $N$,即城市数量。接下来的 $N - 1$ 行,每行包含两个整数 $u$ 和 $v$,表示城市 $u$ 和 $v$ 之间有一条直接道路。

下一行包含 $K$,即 Pablo 网络中最初存在的走私贩数量。接下来的 $K$ 行,每行包含两个数字 $u$ 和 $v$,定义了走私贩的路径。

下一行包含 $Q$,即 Pablo 打算执行的查询数量。接下来的 $Q$ 行,每行包含一个上述格式的查询。

输出格式

对于每个类型为 3 的查询,在单独的一行中输出答案。

数据范围

  • $1 \le N \le 30,000$
  • $0 \le K \le 50,000$
  • $1 \le Q \le 50,000$
  • $0 \le t_1 \le t_2 \le 2,000,000,000$
  • 每个走私贩的路径最多覆盖 20 座城市(包括其端点)。

子任务

测试用例将单独评分。

子任务 分值 额外输入限制
1 15% $N \le 1,000$, $K, Q \le 500$, $0 \le t_1 \le t_2 \le 10$
2 45% $N \le 10,000$, $K, Q \le 5,000$
3 40%

样例

输入 1

5
1 2
2 3
2 4
1 5
1
4 1
3
3 3 5 0 3
1 2 5
3 4 5 1 5

输出 1

2
10

说明 1

走私贩 1 在时间 0 到 3 之间在路径 3-2-1-5 上运送了 2 单位货物: - 时刻 1 在城市 2; - 时刻 2 在城市 1。

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.