Hudson River TradingOA #2
Stock Buy Sell Position Indicator
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationStrings
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.
Input
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
Output n space-separated integers; the initial position is 0.
Example 1
Input:
10 2 3
51 56 56 58 60 59 54 57 52 48
1 1
-1 -1 1
Output:
0 0 0 1 2 2 2 1 1 1
Example 2
Input:
5 2 1
51 56 56 58 58
1 1
-1
Output:
0 0 0 1 1
Example 3
Input:
3 2 2
1 3 2
1 -1
1 -1
Output:
0 0 0
Editorial
Loading solution…