|
||||||||||
HeHeTime Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 590 Accepted Submission(s): 270 Problem Description $$M = \begin{pmatrix} t_{n-1} & t_n & t_{n+1} & \cdots & t_{2*n-3} & t_{2*n-2}\\ t_{n-2} & t_{n-1} & t_n & \cdots & t_{2*n-4} & t_{2*n-3}\\ t_{n-3} & t_{n-2} & t_{n-1} & \cdots & t_{2*n-5} & t_{2*n-4}\\ \vdots & \vdots & \vdots & \ddots & \vdots & \vdots\\ t_1 & t_2 & t_3 & \cdots & t_{n-1} & t_n\\ t_0 & t_1 & t_2 & \cdots & t_{n-2} & t_{n-1}\\ \end{pmatrix}$$ You are expected to write a program to point out some elements of $M*M$. Input Multi test cases (about 100), every case occupies two lines. The first line contains an integer n. Then second line contain 2*n-1 integers $t_0, t_1, t_2, t_3, \ldots, t_{2*n-4}, t_{2*n-3}, t_{2*n-2}$ separated by exact one space. The third line contains an integer m, indicates the number of query. Next m lines will give queries $\begin{matrix} r_0 & c_0\\ r_1 & c_1\\ r_2 & c_2\\ \vdots & \vdots\\ r_{m-1} & c_{m-1} \end{matrix}$ For $r_0, c_0$ the program will query the element of $M*M$ which locates in the $r_0^{th}$ row, $c_0^{th}$ column. For $r_i, c_i(0<i<m)$, assume that the answer of $i-1^{th}$ query is ANS, the program will query the element of $M*M$ which locates in $((r_i+ANS) \% n)^{th}$ row, $((c_i+ANS) \% n)^{th}$ column. Please process to the end of file. [Technical Specification] $1 \leq n \leq 1000$ $0 \leq t_i \leq 100$ $0 \leq r_i, c_i \leq n-1$ $1 \leq m \leq 100000$ Output For each case£Ĵoutput the sum of the answer of each query. Sample Input
Sample Output
Hint $\quad\ \text{For the first case }M = \begin{pmatrix} 3 & 1 & 2\\ 2 & 3 & 1\\ 1 & 2 & 3 \end{pmatrix}$ $\text{For the second case }M = \begin{pmatrix} 2 & 10 & 5 & 7\\ 7 & 2 & 10 & 5\\ 5 & 7 & 2 & 10\\ 10 & 5 & 7 & 2 \end{pmatrix}$ Source | ||||||||||
|