#P16609. [SYSUCPC 2025] Road2

    ID: 16378 Type: RemoteJudge 6000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>2025Kruskal 重构树最近公共祖先 LCA分块高校校赛

[SYSUCPC 2025] Road2

题目描述

The highway system of Province G can be viewed as a weighted undirected graph with nn nodes and mm edges. Each edge represents a segment of the highway, and each node represents a city. Every highway segment is bidirectional. The ii-th highway segment connects the two cities uiu_i and viv_i, with a length of wiw_i kilometers.

Miss Orange\texttt{Miss Orange} is currently commuting in Province G. Her car consumes one unit of fuel per kilometer traveled. Any city has a gas station where the car's fuel tank can be fully refilled, and the fuel consumption of Miss Orange\texttt{Miss Orange}'s car while driving within the city is negligible. Miss Orange\texttt{Miss Orange} has planned qq trips. The ii-th trip starts from city xx and ends at city yy. She wants to know the minimum fuel tank capacity required for this trip.

However, she has not decided on xx and yy but only knows that xx and yy lie within the interval [li,ri][l_i, r_i]. Specifically, for all lix<yril_i \le x < y \le r_i, Miss Orange wants to know the sum of the minimum fuel tank capacities required to travel from xx to yy. Formally, let f(x,y)f(x, y) denote the fuel tank capacity required for a trip starting at xx and ending at yy. You need to output lix<yrif(x,y)\sum\limits_{l_i \le x < y \le r_i} f(x, y).

Since she needs to consider her next plan based on the current one, certain constraints will be imposed on you in the problem.

输入格式

The first line contains two integers n(1n5×104)n(1\leq n \leq 5 \times 10^{4}) and m(1m2×105)m(1 \leq m \leq 2 \times 10^{5}).

The next mm lines each contain three integers u,v(1u,vn),w(1w109)u,v(1\leq u,v\leq n),w(1\leq w \leq 10^{9}), representing an edge between uu and vv with a weight of ww. It is guaranteed that the graph is connected.

Then, one line contains an integer q(1q5×104)q(1\leq q \leq 5 \times 10^4).

The next qq lines each contain two integers l,r(0l,r1018)l',r'(0\leq l',r'\leq 10^{18}), representing the encrypted queries. Each time, you need to XOR the current ll' and rr' with the previous answer to obtain the real ll and rr.The data guarantees that the real ll and rr satisfy 1lrn1 \leq l \leq r \leq n.

输出格式

Output qq lines, each containing one integer representing the answer.

5 10
1 2 13
1 3 13
1 4 12
4 5 11
4 4 7
4 2 10
4 5 13
1 4 8
2 4 8
3 4 8
5
4 4
2 4
28 29
10 10
1 5
0
24
11
0
92