[BOJ 6105] Look Up

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 128M

Problem types
Allowed languages
Assembly, Awk, C, C++, Java, Pascal, Perl, Python, Sed, Text

Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000).</p>

Each cow is looking to her left toward those with higher index numbers. We say that cow i 'looks up' to cow j if i < j and H_i < H_j. For each cow i, FJ would like to know the index of the first cow in line looked up to by cow i.

입력 형식

  • Line 1: A single integer: N
  • Lines 2..N+1: Line i+1 contains the single integer: H_i
  • </ul>

     

    출력 형식

    • Lines 1..N: Line i contains a single integer representing the smallest index of a cow up to which cow i looks. If no such cow exists, print 0.
    • </ul>

       

      예제 입력

6
3
2
6
1
1
2

예제 출력

3
3
0
6
6
0

힌트

Cows 1 and 2 both look up to cow 3; cows 4 and 5 both look up to cow 6; and cows 3 and 6 do not look up to any cow.</p>

 


Comments

There are no comments at the moment.