#P7172. [COCI 2020/2021 #3] Specijacija
[COCI 2020/2021 #3] Specijacija
Description
Given a positive integer and a sequence of positive integers satisfying .
This sequence parameterizes a tree with nodes. The tree has levels, where level contains nodes respectively, as shown in the figure:

It is parameterized by .
Level contains nodes . Node has two children, while all other nodes on the same level have only one child. In each level, children are assigned to nodes in increasing order of node indices, always choosing the smallest-index node in the next level that has not been assigned yet.
Answer queries. For each query, find the lowest common ancestor of and , i.e., the node with the largest index that is an ancestor of both and .
Input Format
The first line contains three integers , representing the number of parameters, the number of queries, and the parameter used to determine node indices.
The second line contains a sequence of length (for each , ).
Each of the next lines contains two integers and ($1 \le \tilde x_i, \tilde y_i \le \frac{(n+1)(n+2)}{2}$), used to determine the node indices involved in the -th query.
Let be the answer to the -th query, and define . The node indices involved in the -th query are:
$$x_i=[(\tilde x_i-1+t \times z_{i-1}) \bmod \frac{(n+1)(n+2)}{2}]+1$$$$y_i=[(\tilde y_i-1+t \times z_{i-1}) \bmod \frac{(n+1)(n+2)}{2}]+1$$Note: When , we have and . When , the node indices involved in the query should be determined using previous answers.
Output Format
Output lines in total. On the -th line, output the lowest common ancestor of and .
3 5 0
1 2 6
7 10
8 5
6 2
9 10
2 3
1
5
1
6
1
3 5 1
1 2 6
7 10
8 5
6 2
9 10
2 3
1
6
2
1
1
Hint
[Sample Explanation #1 / #2]
The shapes of the trees represented by the two samples are already shown in the figure in the problem description.
In the second sample, the node indices involved in each query are:
, ;
, ;
, ;
, ;
, .
[Constraints]
| Subtask | Points | Constraints and Notes |
|---|---|---|
For of the testdata, , and .
[Notes]
The scoring for this problem follows the original COCI problem, with a full score of .
Translated from COCI2020-2021 CONTEST #4 T5 Specijacija.
Translated by ChatGPT 5
京公网安备 11011102002149号