#abc258e. E - Packing Potatoes

E - Packing Potatoes

Score : 500500 points

问题描述

1010010^{100} 个土豆将逐一从传送带上出来。土豆的重量由长度为 NN 的序列 W=(W0,,WN1)W = (W_0, \dots, W_{N-1}) 描述:第 ii 个出来的土豆的重量是 W(i1)modNW_{(i-1) \bmod N},其中 (i1)modN(i-1) \bmod N 表示当 i1i - 1 除以 NN 后的余数。

高桥将会准备一个空箱子,并按照以下方式逐个打包土豆。

  • 将传入的土豆装入箱子中。如果现在箱子里土豆的总重量达到或超过 XX,则封住该箱子并准备一个新的空箱子。

给定 QQ 个查询。在第 ii 个查询 (1iQ)(1 \leq i \leq Q) 中,给出一个正整数 KiK_i,求第 KiK_i 个被封住的箱子中的土豆数量。可以证明,在本问题的约束条件下,至少会有 KiK_i 个被封住的箱子。

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

Problem Statement

1010010^{100} potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence W=(W0,,WN1)W = (W_0, \dots, W_{N-1}) of length NN: the weight of the ii-th potato coming is W(i1)modNW_{(i-1) \bmod N}, where (i1)modN(i-1) \bmod N denotes the remainder when i1i - 1 is divided by NN.

Takahashi will prepare an empty box and then pack the potatoes in order, as follows.

  • Pack the incoming potato into the box. If the total weight of the potatoes in the box is now XX or greater, seal that box and prepare a new empty box.

You are given QQ queries. In the ii-th query (1iQ)(1 \leq i \leq Q), given a positive integer KiK_i, find the number of potatoes in the KiK_i-th box to be sealed. It can be proved that, under the Constraints of the problem, there will be at least KiK_i sealed boxes.

Constraints

  • 1N,Q2×1051 \leq N, Q \leq 2 \times 10^5
  • 1X1091 \leq X \leq 10^9
  • 1Wi109(0iN1)1 \leq W_i \leq 10^9 \, (0 \leq i \leq N - 1)
  • 1Ki1012(1iQ)1 \leq K_i \leq 10^{12} \, (1 \leq i \leq Q)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN QQ XX

W0W_0 W1W_1 \ldots WN1W_{N-1}

K1K_1

\vdots

KQK_Q

Output

Print QQ lines. The ii-th line (1iQ)(1 \leq i \leq Q) should contain the answer to the ii-th query.

Sample Input 1

3 2 5
3 4 1
1
2

Sample Output 1

2
3

Before sealing the 22-nd box, Takahashi will do the following:

  • Prepare an empty box.
  • Pack the 11-st potato into the box. Now, the total weight of potatoes in the box is 33.
  • Pack the 22-nd potato into the box. Now, the total weight of potatoes in the box is 3+4=73 + 4 = 7, which is not less than X=5X = 5, so seal this box.
  • Prepare a new empty box.
  • Pack the 33-rd potato into the box. Now, the total weight of potatoes in the box is 11.
  • Pack the 44-th potato into the box. Now, the total weight of potatoes in the box is 1+3=41 + 3 = 4.
  • Pack the 55-th potato into the box. Now, the total weight of potatoes in the box is 1+3+4=81 + 3 + 4 = 8, which is not less than X=5X = 5, so seal this box.

The 11-st box sealed contains 22 potatoes, and the 22-nd box sealed contains 33 potatoes.

Sample Input 2

10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000

Sample Output 2

4
5
5
5
5

update @ 2024/3/10 10:57:58