AmazonOA #325
Predict Answer
估计中等可在线判题
考点(AI 标注)单调栈与堆
For each 1-based query day i, find among the other days the nearest day j whose price is strictly lower than that day's; if two days are equally near, choose the smaller day number. If there is no strictly cheaper day, output −1. Each query is independent and does not change the prices.
输入格式
The first line contains n q, the second line contains n stockData values, and the third line contains q 1-based days. The original bounds are 1≤n,q≤100000, 1≤stockData[i]≤10^9, 1≤query≤n. The raw restores the conditions stockData[j]<stockData[i] and j≠i, which the HTML had swallowed.
输出格式
Output the q answers in query order, separated by spaces.
样例 1
输入:
10 3
5 6 8 4 9 10 8 3 6 4
6 5 4
输出:
5 4 8
样例 2
输入:
3 2
1 2 1
2 1
输出:
1 -1
样例 3
输入:
2 2
3 3
1 2
输出:
-1 -1
样例说明
The answers are 5 4 8; 1 −1; and −1 −1. An equal price is not lower, and at equal distance the left day wins.