#abc340e. E - Mancala 2

E - Mancala 2

Score: 475475 points

问题描述

NN 个编号为 00N1N-1 的箱子。最初,第 ii 个箱子里包含 AiA_i 个球。

Takahashi 将按照以下顺序对 i=1,2,,Mi=1,2,\ldots,M 执行以下操作:

  • 将变量 CC 设置为 00
  • 从第 BiB_i 个箱子里取出所有球并握在手中。
  • 当手中至少持有一个球时,重复以下过程:
    • CC 的值增加 11
    • 将手中的一颗球放入编号为 (Bi+C)modN(B_i+C) \bmod N 的箱子中。

确定完成所有操作后每个箱子里的球的数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN boxes numbered 00 to N1N-1. Initially, box ii contains AiA_i balls.

Takahashi will perform the following operations for i=1,2,,Mi=1,2,\ldots,M in order:

  • Set a variable CC to 00.
  • Take out all the balls from box BiB_i and hold them in hand.
  • While holding at least one ball in hand, repeat the following process:
    • Increase the value of CC by 11.
    • Put one ball from hand into box (Bi+C)modN(B_i+C) \bmod N.

Determine the number of balls in each box after completing all operations.

Constraints

  • 1N2×1051 \leq N \leq 2\times 10^5
  • 1M2×1051 \leq M \leq 2\times 10^5
  • 0Ai1090 \leq A_i \leq 10^9
  • 0Bi<N0 \leq B_i < N
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A0A_0 A1A_1 \ldots AN1A_{N-1}

B1B_1 B2B_2 \ldots BMB_M

Output

Let XiX_i be the number of balls in box ii after completing all operations. Print X0,X1,,XN1X_0,X_1,\ldots,X_{N-1} in this order, separated by spaces.

Sample Input 1

5 3
1 2 3 4 5
2 4 0

Sample Output 1

0 4 2 7 2

The operations proceed as follows:

Figure

Sample Input 2

3 10
1000000000 1000000000 1000000000
0 1 0 1 0 1 0 1 0 1

Sample Output 2

104320141 45436840 2850243019

Sample Input 3

1 4
1
0 0 0 0

Sample Output 3

1

update @ 2024/3/10 01:33:15

}