#P1380. 奶牛排队

奶牛排队

Description

Bob 的农场养了 <math xmlns="http://www.w3.org/1998/Math/MathML">n 头奶牛,每天奶牛们都要经历漫长的排队打饭的过程。

为了排解长时间排队带来的焦虑,<math xmlns="http://www.w3.org/1998/Math/MathML">Bob 让他的奶牛们玩一个游戏,让每头奶牛找出他的左侧第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 头比自己体重轻的奶牛。

请你编程帮助 <math xmlns="http://www.w3.org/1998/Math/MathML">Bob 计算出答案,方便他验证奶牛们计算的正确性。

Input Format

第 <math xmlns="http://www.w3.org/1998/Math/MathML">1 行输入一个整数 <math xmlns="http://www.w3.org/1998/Math/MathML">n,表示奶牛的数量。(<math xmlns="http://www.w3.org/1998/Math/MathML">1<n106

第 <math xmlns="http://www.w3.org/1998/Math/MathML">2 行有空格隔开的 <math xmlns="http://www.w3.org/1998/Math/MathML">n 个整数 <math xmlns="http://www.w3.org/1998/Math/MathML">ai,代表奶牛的身高(<math xmlns="http://www.w3.org/1998/Math/MathML">1ai105)。

Output Format

输出 n 个整数,用空格隔开,表示每头奶牛左侧第 1 头体重小于自己的奶牛的体重,如果某头奶牛左侧没有比自己轻的奶牛,请输出整数 0
5
50 80 100 90 70
0 50 80 80 50

Source

单调栈 简单问题