#P10783. 【MX-J1-T3】『FLA - III』Anxiety
【MX-J1-T3】『FLA - III』Anxiety
Background
Original link: https://oier.team/problems/J1C。
I came. I saw. I had anxiety. I left.
Problem Description
Given a binary tree with nodes, the weight of node is , and node is the root. For every non-root node , there is an undirected edge connecting node and node . Note that denotes the greatest integer not exceeding .
Define the distance between nodes as the minimum number of edges that must be traversed to go from node to node . Given queries, the -th query provides three positive integers . You need to output the sum of weights of all nodes in the tree whose distances to both nodes and are no more than .
Input Format
The first line contains two positive integers .
The second line contains positive integers; the -th integer is .
The next lines each contain three positive integers on the -th line.
Output Format
Output lines, each containing one integer. The integer on the -th line is the answer to the -th query.
3 3
1 1 1 1 1 1 1
3 4 2
5 4 6
3 2 2
2
7
3
4 5
3 4 10 7 1 6 10 6 16 5 3 16 6 2 9
1 4 6
4 2 1
1 14 5
6 13 3
11 15 2
104
11
74
51
0
Hint
"Sample Explanation #1"

For the first query, the nodes that satisfy the condition are , and the sum of weights is .
For the second query, the nodes that satisfy the condition are , and the sum of weights is .
For the third query, the nodes that satisfy the condition are , and the sum of weights is .
"Constraints"
| Test Point ID | ||||
|---|---|---|---|---|
For of the testdata, , , , , , and . Node indices are integers from to .
Translated by ChatGPT 5