PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000095. Thỏ trên hàng cây (Penchick and Desert Rabbit)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thỏ trên hàng cây (Penchick and Desert Rabbit)
Penchick and Desert Rabbit
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are trees in a row, and tree has height . A rabbit at tree can jump to tree if and , or if and . It may make any number of jumps or stay where it is. For every starting position , determine the maximum height of any tree reachable from it.
Input
The first line contains . The second line contains .
Output
Print integers, one answer for every starting position.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Input
4
2 3 1 4
Output
3 3 3 4
Explanation
The first three trees are mutually reachable; the fourth is not reachable from the first three.