問題一覧 > 通常問題

No.2482 Sandglasses

レベル : / AI推定難易度 : 1500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 72
作問者 : Magentor / テスター : ytqm3
お気に入りにしたユーザー ProblemId : 10143 / 自分の提出
問題文最終更新日: 2023-09-28 19:38:44
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 405 技術室奥プログラミングコンテスト#7 Day1 (順位表) の他の問題:

Problem Statement

There are $N$ sandglasses, each consisting of a part $A$ and a part $B$. Each part can hold at most $K$ grams of sand.

The $i \ (1 \leq i \leq N)$-th sandglass has part $a_i$ on top, with $b_i$ grams of sand in part $A$ and $K-b_i$ grams of sand in part $B$. Sand falls into the lower part at a rate of $1$ gram per $1$ second. Here, the given $b$ satisfies $b_i \neq b_j$ if $i \neq j$.

While the sand in the sandglasses is falling, you repeat the following operations.

  • If the lower part of a sandglass contains $K$ grams of sand, turn it over.
  • If there is a pair of sandglasses with the same amount of sand in part $A$, turn both of them over.

Here, turning over a sandglass is considered to take no time, and the sand starts falling at the moment the sandglass is turned over.

Also, due to the constraints, it never happens that $3$ or more sandglasses have the same amount in part $A$.

Find the amount of sand in part $A$ of each sandglass after $T$ seconds.

Input

$N$ $K$ $T$
$a_1$ $a_2$ $\dots$ $a_N$
$b_1$ $b_2$ $\dots$ $b_N$
  • All input values are integers.
  • $1 \leq N \leq 2 \times 10^5$
  • $2 \leq K \leq 10^{9}$
  • $1 \leq T \leq 10^{9}$
  • $a_i$ is A or B $(1 \leq i \leq N)$
  • $0 < b_i < K \ (1 \leq i \leq N)$
  • $b_i \neq b_j$ when $i \neq j$

Output

Output $N$ values. The $i$-th value should be the amount of sand in part $A$ of sandglass $i$ after $T$ seconds. (Corrected at 21:48)

Sample

Sample 1
Input
2 10 15
B A
6 8
Output
1 7

The operations during the $15$ seconds are as follows.

  • After $1$ second, sandglasses $1$ and $2$ have the same amount of sand in part $A$, $7$ grams, so sandglasses $1,2$ are turned over.
  • After $4$ seconds, the amount of sand in part $A$ of sandglass $2$ becomes $10$ grams, so sandglass $2$ is turned over.
  • After $8$ seconds, the amount of sand in part $B$ of sandglass $1$ becomes $10$ grams, so sandglass $2$ is turned over.
  • After $11$ seconds, sandglasses $1$ and $2$ have the same amount of sand in part $A$, $3$ grams, so sandglasses $1,2$ are turned over.
  • After $14$ seconds, the amount of sand in part $B$ of sandglass $1$ becomes $10$ grams, so sandglass $2$ is turned over.

After $15$ seconds, part $A$ of sandglass $1$ contains $1$ gram of sand, and part $A$ of sandglass $2$ contains $7$ grams of sand.

Sample 2
Input
2 3 3
A B
1 2
Output
1 2
Sample 3
Input
9 1992 2023
A B B A B B A B A
19 289 514 318 537 1722 443 972 114
Output
239 1424 1672 1447 1705 1980 1580 1909 989 

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