博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CodeForces 1272E --- Nearest Opposite Parity】
阅读量:2038 次
发布时间:2019-04-28

本文共 1504 字,大约阅读时间需要 5 分钟。

【CodeForces 1272E --- Nearest Opposite Parity】

题目来源:

Description

You are given an array a consisting of n integers. In one move, you can jump from the position i to the position i−ai (if 1≤i−ai) or to the position i+ai (if i+ai≤n).

For each position i from 1 to n you want to know the minimum the number of moves required to reach any position j such that aj has the opposite parity from ai (i.e. if ai is odd then aj has to be even and vice versa).

Input

The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤n), where ai is the i-th element of a.

Output

Print n integers d1,d2,…,dn, where di is the minimum the number of moves required to reach any position j such that aj has the opposite parity from ai (i.e. if ai is odd then aj has to be even and vice versa) or -1 if it is impossible to reach such a position.

Sample Input

10

4 5 7 6 7 5 4 4 6 4

Sample Output

1 1 1 2 -1 1 1 3 1 1

AC代码:

#include 
using namespace std;#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)#define endl '\n'const int MAXN = 2e5+5;int arr[MAXN],ans[MAXN];vector
v[MAXN];int main(){
SIS; int n; memset(ans,-1,sizeof(ans)); cin >> n; for(int i=0;i
> arr[i]; queue
q; for(int i=0;i
=0) {
v[i-arr[i]].emplace_back(i); if((arr[i]&1)^(arr[i-arr[i]]&1)) ans[i]=1; } if(i+arr[i]

转载地址:http://qsyof.baihongyu.com/

你可能感兴趣的文章
查看天气可用的api
查看>>
如何查看HTTP请求头
查看>>
深入浅出理解JavaScript的闭包概念
查看>>
Linux下安装Tomcat服务器和部署Web应用
查看>>
在Linux里安装、启动nginx
查看>>
MySQL出现1030-Got error 28 from storage engine错误
查看>>
git push.default 的设置
查看>>
git 基本操作记录
查看>>
ArrayBlockingQueue和LinkedBlockingQueue的区别
查看>>
Spring Boot配置的第一个应用(如何启动)
查看>>
Spring Boot中使用@Async实现异步调用
查看>>
Netty 源码分析之 三 我就是大名鼎鼎的 EventLoop(一)
查看>>
submit与execute区别
查看>>
导入一个maven工程后一直显示importing maven projects
查看>>
eclipse 把当前git目录中项目关联上git
查看>>
Eclipse中用git解决冲突----避免每次重新拉代码
查看>>
Springboot 之 自定义配置文件及读取配置文件
查看>>
服务器端判断request来自Ajax请求(异步)还是传统请求(同步)
查看>>
git adding files to index has encountered a problem
查看>>
git学习六:git提交忽略不必要的文件或文件夹
查看>>