QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 512 MB Total points: 100

#7459. rpdq

统计

给定一棵 $n$ 个节点的无根,有边权的树,每个点有个编号,编号为一个 $1 \sim n$ 的排列。

共 $m$ 组询问,每次询问给出 $l,r$,求所有点编号的二元组 $(i,j)$ 满足 $l \le i < j \le r$ 在树上的距离的和,两个点的距离定义为连接其的简单路径上的所有边的边权和。

输入格式

第一行两个空格隔开的数 $n$ $m$。

之后 $n-1$ 行,每行三个空格隔开的数 $u$ $v$ $d$ 表示一条 $u$ 和 $v$ 之间边权为 $d$ 的边。

之后 $m$ 行,每行两个空格隔开的数 $l$ $r$ 表示一次询问。

输出格式

共 $m$ 行,表示每个询问对应的答案,答案对 $2^{32}$ 取模。

样例数据

样例输入

6 6
2 1 1
5 1 1
3 1 3
4 5 1
6 3 3
2 5
1 5
1 4
3 6
2 6
1 1

样例输出

19
26
18
28
44
0

子任务

Idea:nzhtl1477,Solution:nzhtl1477,Code:zx2003,Data:nzhtl1477

对于 $100\%$ 的数据,$1\le n,m,d\le 2\cdot 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.