Hudson River TradingOA #2
Stock Buy Sell Position Indicator
估计中等可在线判题
考点(AI 标注)模拟/实现字符串
Update a position using price-change signals. A rise counts as +1 and a fall as -1; an unchanged price produces no signal and does not break the preceding sequence of non-zero changes. Whenever the most recent change sequence matches buyIndicator, the position increases by 1; whenever it matches sellIndicator, the position decreases by 1. When both signals match at the same position, they cancel out. Output the position after each price moment.
The original example 51,56,56,58 clearly treats the two rises as consecutive signals; an unchanged price neither triggers a signal nor resets the non-zero change sequence. The upstream compiled MDX version's handling of direction 0 conflicts with this original example; this site follows the original rule and example and records the discrepancy.
输入格式
The first line contains n b s (1≤n≤200000, 1≤b,s≤n); then come n non-negative prices (≤10^9), b values of +1/-1 and s values of +1/-1.
输出格式
Output n space-separated integers; the initial position is 0.
样例 1
输入:
10 2 3
51 56 56 58 60 59 54 57 52 48
1 1
-1 -1 1
输出:
0 0 0 1 2 2 2 1 1 1
样例 2
输入:
5 2 1
51 56 56 58 58
1 1
-1
输出:
0 0 0 1 1
样例 3
输入:
3 2 2
1 3 2
1 -1
1 -1
输出:
0 0 0