F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

HeHe

Time 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
3 1 2 3 1 2 2 0 0 1 2 4 10 5 7 2 10 5 7 3 1 2 3 0 2 1 2 1 2 3 4 0 0 0 1 1 0 1 1
 

Sample Output
23 348 22
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 13:17:27, Gzip enabled