Nano-ant


  • Time Limit : 4 seconds
  • Memory Limit : 512 megabytes

Science grows faster nowadays more than ever and scientific achievements increase more and more! One of the greatest achievements in the field of nano technology is being made by a company founded by Shengdebao's brother. The company's name is *"BAOCompany"* and their new project revolves around tiny ants called nano-ants. Here's some details about them:

Nono-ants should be kept in a form of prism with a regular nn-sided polygon base with the height of 11 meters it means if we look at the prism from above we will see a regular nn sided polygon and if we put it on the ground it will be 11 meters high. The nn vertical edges of the prism are numbered from 00 to n1n-1 in clockwise order. There exists a special nano-needle that can put delicate holes on the edges of the prism with nano-meter accuracy. After creating each hole exactly one nano-ant can occupy that hole. In fact each hole can be represented by two integer numbers (i,j)(i , j) such that 0i<n0 \le i \lt n and 1j1091 \le j \le 10^9 meaning the hole is on the iith edge and in height jj nano-meters.

Baoium, the material used to make the prism, is quite fragile and can't have more than n×nn \times n holes on it. Also at the beginning the prism has exactly one hole placed on each edge.

Nano-ant movements are impressive! Their movements are in the form of kk-patrols each kk-patrols takes kk days. At the morning of everyday the ant starts from one hole on an edge, the ants takes a peek from the hole to the next edge in clockwise order and chooses the closest to it. If multiple closest holes exists, he chooses one with the lowest height. Then he starts traversing the intended side through a straight line. Nano-ants are tiny so it takes them one day to pass that side and when they reach the next hole in the next edge they become tired and rest in that hole for the night starting tomorrow morning from that hole again. Now in a kk-patrol this continues for kk days, a kk-patrol's result is the hole in which the ant rests in the last night.

Scientist are testing some of nano-ants properties, their research contains qq stages in each stage they either create a new hole on the prism, or they want to know the result of a specific kk-patrol. kk can be a large number so they asked you, their programmer, to help them with this problem.

Input🔗

In the first line of input comes number nn, the number of sides on the prism. Then in the next line nn numbers are given in the row number ii is equal to aia_i indicating the initial hole (i1,ai)(i-1 , a_i) on the iith edge.

In the third line you should receive number qq, the number of researches that should be done. next qq lines are in two formats:

  • 1 i j1 \ i \ j meaning a new hole should be created on height jj of the iith edge. (0i<n,1j109)(0 \le i \lt n , 1 \le j \le 10^9)
  • 2 i j k2 \ i \ j \ k you should output the result of a kk-patrol commencing from hole (i,j)(i,j) as a pair of integers (0i<n,1j109,0k1012)(0 \le i \lt n , 1 \le j \le 10^9 , 0 \le k \le 10 ^ {12})

It is guaranteed that the first type researches do not repeat and every time a new hole is created. Also, the next type of research always refers to a preceding created hole and not a hole not yet made.

3n300 3 \le n \le 300 0qn×nn 0 \le q \le n \times n - n

Output🔗

For any type two query in one line output the hole as a pair i ji \ j showing the result of the related patrol.

Examples🔗

Sample input 1🔗

4
1 1000000000 1 1000000000
4
2 0 1 3
2 0 1 14
1 1 1
2 0 1 999999999997
Plain text

Sample output 1🔗

3 1000000000
2 1
1 1
Plain text

Explanation: Before the addition of the new hole each hole has a unique destination on the next edge and the answer is uniquely determined from k mod nk \ mod \ n. After adding the new hole in the last patrol, by passing over 999 999 999 996999\ 999\ 999\ 996 sides the ant then returns to its former place (1,0)(1 , 0) and in the next stage it goes to the next closest hole (the new hole) (1,1)(1 , 1).

Sample input 2🔗

3
10 9 10
6
1 0 6
1 1 4
1 1 11
1 2 8
1 2 12
2 0 10 4
Plain text

Sample output 2🔗

1 4
Plain text

Explanation : The ant in this patrol goes to heights 98649 \to 8 \to 6 \to 4 respectively

ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.