Ensure that you are logged in and have the required permissions to access the test.

Doraemon and queries

3.9

37 votes
Hard
Problem

Doraemon has an array A of N positive integers. He asks Q queries on this array. Each queries are of type : L, R, X, K. For query P and Q are generated from L, R and answer for query (suppose previous_query_answer) as following pseudocode:

P = (L + previous_query_answer) % N + 1
Q = (R + previous_query_answer) % N + 1
if ( ) swap(P, Q)

For 1st query previous_query_answer = 0.
Answer to the query is count of all elements Y in subarray such that . Show him that you are a pro by answering the queries.

Input Format :

First line of input contains integer N - size of array. Next line contains N integers of array. Next line contains integer Q - number of queries. Next Q line contains queries of type : L R X K as mentioned in problem statement.

Output Format :

For each query print the required answer per line.

Constraints :

1 <= N <=
1 <= Q <=
1 <= <=
1 <= L <= R <=
0 <= <=

Setter : Tanmay Patel

Tester: Mohib Manva

Sample Input
10
3 2 4 2 5 8 6 7 10 1
4
1 6 2 3
3 5 5 2
1 4 3 0
5 10 8 3
Sample Output
4
1
0
2
Time Limit: 4
Memory Limit: 256
Source Limit:
Editor Image

?