Description

You are given the array of integer numbers a0, a1, ..., an - 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.

Input

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Output

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

Examples
input
9
2 1 0 3 0 0 3 2 4
output
2 1 0 1 0 0 1 2 3 
input
5
0 1 2 3 4
output
0 1 2 3 4 
input
7
5 6 0 1 -2 3 4
output
2 1 0 1 2 3 4 
题意:求距离0最近的距离
解法:找距离最近的0,可能是左边或者右边的0,取最近的
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
vector<ll>x,y;
ll n;
ll num[];
ll a[];
long long sum;
int main()
{
cin>>n;
for(int i=;i<=n;i++)
{
cin>>num[i];
if(num[i])
{
x.push_back(i);
}
else
{
y.push_back(i);
}
}
for(int i=;i<x.size();i++)
{
int pos=lower_bound(y.begin(),y.end(),x[i])-y.begin();
//cout<<pos<<endl;
if(pos==) pos++;
if(pos<=y.size()&&pos>=)
{
a[x[i]]=min(abs(x[i]-y[pos]),abs(x[i]-y[pos-]));
}
}
for(int i=;i<=n;i++)
{
cout<<a[i]<<" ";
}
return ;
}

Educational Codeforces Round 20 B的更多相关文章

  1. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  2. Educational Codeforces Round 20 D. Magazine Ad

    The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...

  3. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  4. Educational Codeforces Round 20.C

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Educational Codeforces Round 20 C 数学/贪心/构造

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  6. Educational Codeforces Round 20 C. Maximal GCD

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Educational Codeforces Round 20 B. Distances to Zero

    B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Educational Codeforces Round 20 A. Maximal Binary Matrix

    A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

随机推荐

  1. Java堆内存与栈内存对比

    在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有什么异同,以及和数据结构中的堆栈有何关系? 一.Java 堆存储空间 堆内存(堆存储空间)会在Java运行时分配 ...

  2. ViewFlow增强onItemClick功能及ViewFlow AbsListView源代码分析

    先看实现效果,上图:  ViewFlow是一个非常好用的,用于不确定item个数的水平滑动切换的开源项目. 可是从github上下载的ViewFlow事实上是不支持onItemClick功能的,tou ...

  3. POJ 2886 Who Gets the Most Candies?(树状数组+二分)

    题目链接 注意题目中给的顺序是顺时针的,所以在数组中应该是倒着存的.左就是顺时针,右就是逆时针.各种调试之后,终于A了,很多种情况考虑情况. #include <cstring> #inc ...

  4. hive增加Update、Delete支持

    一.配置hive-site.xml二.建表三.操作四.总结 一.配置hive-site.xml CDH版本先进入Hive配置页 选择高级,找到hive-site.xml 的 Hive 客户端高级配置代 ...

  5. 20170223-问题001,增强中的E消息 显示为 S模式消息,

     MM01 的屏幕增强,里面写的      MESSAGE e056(z1) WITH '供应链计划(SCP) 储备物料与当期物料不能同时选择.'.可是现实出来是S 消息模式,这是为什么?系统转换了吗 ...

  6. 对于iOS 7 隐藏特性和解决之道

    当 iOS7 刚发布的时候,全世界的苹果开发人员都立马尝试着去编译他们的app,接着再花上数月的时间来修复任何出现的故障,甚至重做app.这样的结果,使得人们根本无暇去探究 iOS7 所带来的新东西. ...

  7. react native 之 redux

    第一章  认识redux 说的通俗且直白一点呢,就是redux提供了一个store,独立的一个内存区,然后放了一些state,你可以在任何component中访问到state,这些state要更改怎么 ...

  8. HDU3416 Marriage Match IV —— 最短路径 + 最大流

    题目链接:https://vjudge.net/problem/HDU-3416 Marriage Match IV Time Limit: 2000/1000 MS (Java/Others)    ...

  9. dedecms时间格式调用标签汇总

    1.时间格式{dede:field name='pubdate' function='strftime("%Y年%m月%d日 %H:%M:%S","@me")' ...

  10. LA-3905 (扫描线)

    题意: 给一些流星的初始位置和运动向量,给了相机的拍摄范围;问你最多能拍到多少颗流星; 思路: 将流星用出现在相机拍摄范围内的时间段表示;sort后在扫面端点更新最大值; Ac代码: #include ...