#C2639. Consecutive Happy Events
Consecutive Happy Events
Consecutive Happy Events
You are given a series of events and a corresponding list of worker's preferences for those events. The preferences are represented using binary values, where 1 indicates that the worker liked the event and 0 means otherwise. Starting from the second event, your task is to compute the count of consecutive liked events ending at each event position.
More formally, let \(p_i\) be the preference for the \(i^{th}\) event. Then, for every event \(i\) with \(2 \leq i \leq n\), define the consecutive count \(c_i\) as:
[ c_i = \begin{cases} ; c_{i-1}+1, & \text{if } p_i = 1 \text{ and } p_{i-1} = 1, \ ; 1, & \text{if } p_i = 1 \text{ and } p_{i-1} \neq 1, \ ; 0, & \text{if } p_i = 0. \end{cases} ]
Your program should read from standard input and write the result to standard output.
inputFormat
The input is given via standard input as follows:
- The first line contains an integer \(n\) indicating the total number of events.
- The second line contains \(n\) space-separated integers representing the events (although the actual event values are not used in the computation).
- The third line contains \(n\) space-separated integers (each either 0 or 1) representing the worker's preferences for the corresponding events. Here, 1 means the event is liked.
outputFormat
Output \(n-1\) integers separated by spaces. The \(i^{th}\) integer (1-indexed, starting from the second event) represents the count of consecutive liked events up to and including the current event.
## sample7
1 2 2 3 3 3 4
1 1 0 1 1 1 1
1 0 1 2 3 4