Rotate and Speak Game
Practice
5 (1 votes)
Modular arithmetic
Number theory
Hiring
Easy
Mathematics
Mathamatics
Problem
56% Success 2560 Attempts 20 Points 3s Time Limit 256MB Memory 1024 KB Max Code

$$N$$ children are playing a game of Rotate and Speak. In this game all the children are given a number plate which contains distinct values and they need to form a circle in clockwise order.

There are $$Q$$ turns in this game. In each turn two numbers $$a$$ and $$b$$ are announced. The rules of the game are as follows :

  1. If the number $$a$$ is equal to 1 then it means that all the children shift $$b$$ steps in anti clockwise direction.
  2. If the number $$a$$ is equal to 2 then it means that all the children shift $$b$$ steps in clockwise direction.
  3. If the number $$a$$ is equal to 3 then it means that the child who is standing at  position $$b$$ in the clockwise order speaks the number on his number plate. Note that the positions are from $$0$$ to $$N-1$$ not $$1$$ to $$N$$

Input format:
First line contains an intege $$T$$ that denotes the number of test cases
First line in every test case contains an integer $$N$$ denoting the count of children playing the game.
Second line in every test case contains $$N$$ space separated integers , here the $$i^{th}$$ integer is the number on the number plate of the student $$i$$
Third line in every test case contains an integer $$Q$$,number of turns in the game.
Following $$Q$$ lines ,each contain two integers describing one of the $$3$$ types of moves in a turn.

Output format:
For each moves of type 3, you have to print the number that will be spoken in that turn of the game.

Constraints:

\(1 \le T \le 20\)

\(1 \le N,Q \le 10^{5} \)

\(1 \le a \le 3\)

\(0 \le b \le N-1\)

Note- Since input files are large, use fast input/output methods.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
Tags:
EasySimple-math
Points:20
30 votes
Tags:
Modular arithmeticad-hocNumber TheoryEasyMathematicsBrute-force search簡単
Points:20
1 votes
Tags:
Easy