CF1272E.Nearest Opposite Parity

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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).

输入格式

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 .

输出格式

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 1 2 -1 1 1 3 1 1 
    
首页