InstacartOA #1
Balloon Color Pairs
Estimated MediumJudge-ready
Topics (AI-labelled)In-place ArraysSimulation
Positions are initially uncolored; each query colors a position with a given color (overwriting is allowed). After each query, count the pairs of adjacent positions that are both colored and have the same color.
Input
length,q≤200000, followed by q lines of a 0-based index and a positive color value.
Output
The count after each operation.
Example 1
Input:
5 4
0 1
1 1
2 1
1 3
Output:
0 1 2 0
Example 2
Input:
1 2
0 4
0 4
Output:
0 0
Example 3
Input:
3 3
0 2
2 2
1 2
Output:
0 0 2
Editorial
Loading solution…