No.2662 Installing Cell Towers
タグ : / 解いたユーザー数 23
作問者 :
ymmtr(せるたわーしーぷ!)
/ テスター :
aplysiaistp
Problem Statement
There is a sequence $A=(a_1,a_2,\dots,a_N)$ of length $N$. Initially, all elements of this sequence are $0$.
Also, two sequences of length $M$ are given as $P=(p_1,p_2,\dots,p_M),Q=(q_1,q_2,\dots,q_M)$.
Now, for each integer $i=1,2,\dots,M$, perform the following operation:
- For each integer $j=1,2,\dots,N$, let $d=|p_i-j|$, and add $max(0,q_i-d)$ to $a_j$.
Find the value of each element of the sequence $A$ after all these operations are finished.
Input
$N\ M$ $p_1\ q_1$ $p_2\ q_2$ $\vdots$ $p_M\ q_M$
The input satisfies all of the following constraints.
- $1\le N \le 10^5$
- $1\le M \le 10^5$
- $1\le p_i \le N$
- $1\le q_i \le 10^9$
- All inputs are integers.
Output
Output $a_1,a_2,\dots,a_N$ in order from left to right, separated by spaces.
Print a newline at the end.
Sample
Sample 1
Input
8 1 4 2
Output
0 0 1 2 1 0 0 0
In this case, only the operation for $i=1$ is performed. Here, $q_i=q_1=2$.
For $j=1,2,6,7,8$, we have $d=|p_i-j|=|4-j|\ge 2$ in every case, so $max(0,q_i-d)=max(0,2-d)=0$ is added to $a_j$.
For $j=3,5$, we have $d=1$ in both cases, so $max(0,q_i-d)=max(0,2-1)=1$ is added to $a_j$.
For $j=4$, we have $d=0$, so $max(0,q_i-d)=max(0,2-0)=2$ is added to $a_j$.
From the above, the final sequence $A$ is as shown above.
Sample 2
Input
8 1 2 3
Output
2 3 2 1 0 0 0 0
Perform the operations in the same way as in Sample 1.
Sample 3
Input
9 2 1 100 9 100
Output
192 192 192 192 192 192 192 192 192
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。