#K57832. Post Final Score Calculation
Post Final Score Calculation
Post Final Score Calculation
You are given a sequence of events that affect the scores of posts on a social platform. The events are processed in the order they are received. There are three types of events:
- 1: Create a new post with an initial score of 0.
- 2: Upvote the most recently created post (increase its score by 1).
- 3: Downvote the most recently created post (decrease its score by 1).
If an upvote or downvote event is received before any post is created, it is ignored. At the end of processing each test case, output the scores of all posts in the order they were created, separated by a space. If no post was created in a test case, output an empty line.
The actions modify the score of the current (most recent) post. Formally, let the events be represented as a sequence \(e_1, e_2, \dots, e_n\). When an event \(e_i = 1\) occurs, a new post is created with an initial score of 0. For an event \(e_i = 2\) (upvote) or \(e_i = 3\) (downvote), if at least one post exists, the score of the most recent post (the one created by the latest event \(e_j = 1\) where \(j \le i\)) is incremented by 1 in the case of an upvote, or decremented by 1 in the case of a downvote.
inputFormat
The input is read from stdin and has the following format:
T n1 e1,1 e1,2 ... e1,n1 ... nT eT,1 eT,2 ... eT,nT
Here, T
is the number of test cases. For each test case, the first integer n
denotes the number of events, followed by n
integers representing the events.
outputFormat
For each test case, output a single line containing the final scores of all posts (in the order they were created) separated by a space. If no post was created in a test case, output an empty line.
## sample3
5
1 2 2 3 1
4
2 1 3 2
2
1 1
1 0
0
0 0
</p>