#P11098. [ROI 2022] 滑梯 (Day 1)
[ROI 2022] 滑梯 (Day 1)
Problem Description
Translated from ROI 2022 D1T3.
Peppa and her little brother George came to a water park. George likes sliding down a slide. This slide can be described as a part of a triangular grid, where the vertices are nodes of the slide. At each node, you can choose which pipe to go through next—down-left or down-right. The slide is numbered from top to bottom, starting from level . At level , the slide has only one node; at level , it has two nodes; at level , it has nodes. In total, there are levels. Each ride from top to bottom goes through exactly pipes. Each node has coordinates, represented by two numbers , meaning the -th node from the left on level (). Note that both the levels and the nodes within each level are numbered starting from . If George is at node and slides down-left, he will move to node . If he slides down-right, he will move to node .
Here is a slide with levels ():

George wants to slide down the slide times. Before each ride, Peppa gives him an instruction telling him how to slide along the slide. Each instruction consists of exactly commands, each being either “down-left” or “down-right”. George follows Peppa’s commands, moving from his current node to the next node. The first instruction contains only “down-right” commands. Peppa is too lazy to come up with new instructions, so the instructions for two consecutive rides differ in exactly one command: to get from the -th instruction to the -th instruction, you need to change the -th (not the -th) command from “down-right” to “down-left”. Each command is changed exactly once. In the end, the -th instruction will contain only “down-left” commands. It can be proven that during these rides, George will pass through every node of the slide (but not every pipe).
On the way back from the water park, George encountered the following problem. First, consider the set of all pipes that he has slid through. You are given the coordinates of two nodes: and . You need to determine the coordinates of a node such that starting from this node, using only the pipes he slid through, it is possible to reach both node and node . Among all such nodes, it must be the lowest one, i.e. the value of is as large as possible. It can be proven that such a node always exists and is unique.
George has many queries, but since he has already left the water park, he cannot touch this slide anymore. He needs your help to answer all his queries.
Input Format
The first line contains an integer ().
The second line contains integers (), where is the index of the command that will be changed after the -th ride. It is guaranteed that all are distinct.
The third line contains an integer (), the number of George’s queries.
Each of the next lines contains four integers (, , ), representing the coordinates of the two nodes in the -th query.
Output Format
Output lines. For each query, output two integers and , the coordinates of the answer node for the -th query.
3
2 3 1
5
3 3 3 0
2 2 2 1
1 0 3 1
3 1 3 2
2 2 2 2
0 0
1 1
0 0
2 1
2 2
Hint
Sample Explanation:
The routes of George’s four rides are as follows:

So the set of all pipes he passed through is as follows:

The answers to the five queries can be easily obtained from the figure.
Constraints:
| Subtask | Points | Special Property | ||
|---|---|---|---|---|
| For all , | ||||
| The array has a special form | ||||
In Subtask , the array has the form , where .
Translated by ChatGPT 5