#K32812. Toggle Lights Simulation
Toggle Lights Simulation
Toggle Lights Simulation
In this problem, you are given a row of (N) lights, all initially switched off. You need to perform (Q) operations. Each operation is described by two integers (L) and (R) representing the range (inclusive) of lights to toggle. Toggling a light means changing its state from off (0) to on (1) or from on (1) to off (0). After performing all operations, output the final state of all (N) lights as a sequence of integers.
For example, if (N = 5) and the operations are ((1, 3)), ((2, 4)), and ((3, 5)), then the final states of the lights will be: 1 0 1 0 1.
inputFormat
The first line contains two integers (N) and (Q) where (N) is the number of lights and (Q) is the number of operations. The next (Q) lines each contain two integers (L) and (R), indicating that the lights from position (L) to (R) (inclusive) should be toggled.
outputFormat
Output a single line with (N) space-separated integers representing the final state of each light (0 for off and 1 for on).## sample
5 3
1 3
2 4
3 5
1 0 1 0 1