問題一覧 > 通常問題

No.1097 Remainder Operation

レベル : / AI推定難易度 : 900 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 220
作問者 : SSRS / テスター : 沙耶花
お気に入りにしたユーザー ProblemId : 4385 / 自分の提出
問題文最終更新日: 2020-06-25 22:19:36
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 254 (順位表) の他の問題:

Problem Statement

There is an integer $X$. The initial value of $X$ is $0$. You are also given a sequence $A_0,A_1,\cdots,A_{N-1}$ of length $N$.
From now on, the following operation will be performed repeatedly.

Operation: Compute the remainder of $X$ divided by $N$, and let it be $r$. Add $A_r$ to $X$.

There are $Q$ queries. In each query, a positive integer $K$ is given, so find the value of $X$ after the $K$-th operation.

Input

$N$
$A_0 \ A_1 \ \cdots \ A_{N-1}$
$Q$
$K_1$
$K_2$
$\vdots$
$K_Q$

The input satisfies the following constraints.

  • All input values are integers
  • $1 \leq N \leq 10^5$
  • $1 \leq A_i \leq 10^6 (0 \leq i < N)$
  • $1 \leq Q \leq 10^5$
  • $1 \leq K_i \leq 10^{12} (1 \leq i \leq Q)$

Output

Output $Q$ lines.
On the $i (1 \leq i \leq Q)$-th line, output the value of $X$ after the $K_i$-th operation.

Sample

Sample 1
Input
5
3 3 2 4 7
2
2
4
Output
7
16

In the $1$-st operation, $r=0$, so $X=0+A_0=0+3=3$.
In the $2$-nd operation, $r=3$, so $X=3+A_3=3+4=7$.
In the $3$-rd operation, $r=2$, so $X=7+A_2=7+2=9$.
In the $4$-th operation, $r=4$, so $X=9+A_4=9+7=16$.
Therefore, the values of $X$ after the $2$-nd and $4$-th operations are $7, 16$ respectively, so output $7$ and $16$.

Sample 2
Input
2
314159 141421
1
271828
Output
61919700120 

Be careful of overflow.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。