luogu#P4828. Nagisa loves Tomoya
Nagisa loves Tomoya
Problem Description
Cute Furukawa Nagisa gets a sequence. She defines one operation as changing all to . Then she will ask you queries. Each query gives , meaning: after the -th operation, what is the value of the element at position .
This problem is too easy, and our Nagisa solved it effortlessly. Can you solve it too?
Input Format
An integer , representing the length of the sequence.
The next line contains integers, representing this sequence.
The next line contains an integer , representing the number of queries.
The next lines each contain two integers , with the meaning as described in the statement.
Output Format
Output lines. Each line contains one integer, the answer to the query. Please output the result modulo .
5
1 2 3 4 5
2
1 2
2 2
5
12
Hint
For of the testdata, it holds that:
For of the testdata:
For of the testdata, it holds that:
Translated by ChatGPT 5