#4679. [USACO09MAR] Look Up S

[USACO09MAR] Look Up S

题目描述

Farmer John's N(1N105)N(1 \le N \le 10^5) cows, conveniently numbered 11 to NN, are once again standing in a row. Cow ii has height Hi(1Hi106)H_i(1 \le H_i \le 10^6).

Each cow is looking to her right toward those with higher index numbers. We say that cow ii "looks up to" cow jj if i<ji < j and Hi<HjH_i < H_j. For each cow ii, FJ would like to know the index of the first cow in line "looked up to" by cow ii.

Note: about 50%50\% of the test data will have N103N \le 10^3.

约翰的 N(1N105)N(1\le N\le10^5) 头奶牛站成一排,奶牛 ii 的身高是 Hi(1Hi106)H_i(1\le H_i\le10^6)。现在,每只奶牛都在向右看。对于奶牛 ii,如果奶牛 jj 满足 i<ji<jHi<HjH_i<H_j,我们可以说奶牛 ii 可以仰望奶牛 jj。 求出每只奶牛离她最近的仰望对象。

输入格式

Input

Line 11 : A single integer: NN.

Lines 22 to N+1N+1 : Line i+1i+1 contains the single integer: HiH_i.

11 行输入 NN,之后 NN 行第 i+1i+1 行输入一个身高 HiH_i

输出格式

Lines 11 to NN: Line ii contains a single integer representing the smallest index of a cow up to which cow ii looks. If no such cow exists, print 00.

NN 行,按顺序每行输出一只奶牛的最近仰望对象,如果没有仰望对象,输出 00

输入输出样例 #1

输入 #1

6
3
2
6
1
1
2

输出 #1

3
3
0
6
6
0

说明/提示

FJ has six cows of heights 33, 22, 66, 11, 11, and 22.

Cows 11 and 22 both look up to cow 33; cows 44 and 55 both look up to cow 66. Cows 33 and 66 do not look up to any cow.

【输入说明】66 头奶牛的身高分别为 33, 22, 66, 11, 11, 22

【输出说明】奶牛 1122 仰望奶牛 33,奶牛 4455 仰望奶牛 66,奶牛 3366 没有仰望对象。

【数据规模】

对于 20%20\% 的数据:1N101\le N\le10

对于 50%50\% 的数据:1N1031\le N\le10^3

对于 100%100\% 的数据:1N105,1Hi1061\le N\le10^5,1\le H_i\le10^6