CF1272E.Nearest Opposite Parity

传统题 时间 2000 ms 内存 256 MiB 10 尝试 1 已通过 1 标签

Nearest Opposite Parity

CF1272E · Nearest Opposite Parity

英文原题面

Statement

You are given an array aa consisting of nn integers. In one move, you can jump from the position ii to the position iaii - a_i (if 1iai1 \le i - a_i) or to the position i+aii + a_i (if i+aini + a_i \le n). For each position ii from 11 to nn you want to know the minimum the number of moves required to reach any position jj such that aja_j has the opposite parity from aia_i (i.e. if aia_i is odd then aja_j has to be even and vice versa).

Input

The first line of the input contains one integer nn (1n21051 \le n \le 2 \cdot 10^5) — the number of elements in aa. The second line of the input contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain1 \le a_i \le n), where aia_i is the ii-th element of aa.

Output

Print nn integers d1,d2,,dnd_1, d_2, \dots, d_n, where did_i is the minimum the number of moves required to reach any position jj such that aja_j has the opposite parity from aia_i (i.e. if aia_i is odd then aja_j has to be even and vice versa) or -1 if it is impossible to reach such a position.

样例

样例 1

输入:

10
4 5 7 6 7 5 4 4 6 4

输出:

1 1 1 2 -1 1 1 3 1 1 

在线编程 IDE

建议全屏模式获得最佳体验