Skokovi

면접 대비

시간 제한5초메모리 제한1024 MB

요약
높이 배열과 한계 K가 주어질 때, 1번 위치에서 시작해 오른쪽으로만 이동하며 높이 차가 K 이하인 점프로 각 위치에 도달할 수 있는지 판별한다.
난이도

보통10점 중 6점

유형
그리디, 동적 계획법, 배열, 세그먼트 트리
정답자
아직 제출이 없습니다

문제

In a land who knows where, in a world who knows when, lives a bee named Maya. Her adventure-filled life is an endless source of ideas for tasks, so we chose one of them.

Maya’s friend, a grasshopper named Filip, is preparing for the Olympics in flower jumping. The flowers in the meadow can be represented as a sequence of positive intergers aa of length NN. The height of each flower is given by the number a_ia\_i.

Filip always jumps from left to right. Additionally, since this whole sport is new to him, he cannot jump to a flower whose height differs too much from the one he is currently on. Specifically, from flower ii, he can jump to flower jj if and only if i<ji < j and ∣a_i−a_j∣≤K|a\_i - a\_j | ≤ K, where KK is a positive integer given in the input.

Help Maya plan Filip’s training by determining which flowers Filip can reach if he starts on the leftmost flower. In other words, for each flower, determine if there is a sequence of jumps that leads to it, starting from the first flower.

입력

The first line contains positive integers NN (1≤N≤2⋅1051 ≤ N ≤ 2 \cdot 10^5) and KK (1≤K≤1091 ≤ K ≤ 10^9). The second line contains a sequence of positive integers a, i.e., NN numbers a_ia\_i (1≤a_i≤1091 ≤ a\_i ≤ 10^9), representing the heights of the flowers.

출력

In a single line, output NN numbers, either 00 or 11, where each number indicates whether the corresponding flower is reachable. The number 00 means that it is not possible to reach that flower, while 11 means the flower is reachable. The first flower is always reachable as Filip starts from there.

예제2

  1. 예제 1

    입력
    5 2
    5 4 8 7 2
    
    예상 출력
    1 1 0 1 1
    
  2. 예제 2

    입력
    5 3
    10 15 14 8 9
    
    예상 출력
    1 0 0 1 1