304204: CF803B. Distances to Zero

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Distances to Zero

题意翻译

给定一个数列$a_0,a_1,...,a_{n-1}$ 。对于数列中的每一项都要求出与该项最近的$0$ 与该项的距离。保证数列中有至少一个$0$ 。

题目描述

You are given the array of integer numbers $ a_{0},a_{1},...,a_{n-1} $ . For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

输入输出格式

输入格式


The first line contains integer $ n $ ( $ 1<=n<=2·10^{5} $ ) — length of the array $ a $ . The second line contains integer elements of the array separated by single spaces ( $ -10^{9}<=a_{i}<=10^{9} $ ).

输出格式


Print the sequence $ d_{0},d_{1},...,d_{n-1} $ , where $ d_{i} $ is the difference of indices between $ i $ and nearest $ j $ such that $ a_{j}=0 $ . It is possible that $ i=j $ .

输入输出样例

输入样例 #1

9
2 1 0 3 0 0 3 2 4

输出样例 #1

2 1 0 1 0 0 1 2 3 

输入样例 #2

5
0 1 2 3 4

输出样例 #2

0 1 2 3 4 

输入样例 #3

7
5 6 0 1 -2 3 4

输出样例 #3

2 1 0 1 2 3 4 

Input

题意翻译

给定一个数列$a_0,a_1,...,a_{n-1}$ 。对于数列中的每一项都要求出与该项最近的$0$ 与该项的距离。保证数列中有至少一个$0$ 。

加入题单

算法标签: