Playing with light switches
Algorithm

The solution is brute force. It has a time complexity of \$O(N R)\$ (where \$N\$ is a number of bulbs and \$R\$ a number of ranges) and I expect to take forever on a bonus input (I gave up after 5 minutes).

To get the correct solution you should first realize that flipping switches in [x, y] range has the same net result as flipping switches in [x, N) range followed by flipping switches in [y+1, N) range. Next, since the flippings commute, it doesn't matter in which order they are performed. Each flipping is an edge changing state of all switches to the right of it.

Which brings the correct solution, in pseudocode:

    set up a vector of integers representing edges
    for each input range (x, y)
        push min(x, y)
        push max(x, y) + 1
    sort the vector
    scan integers from 0 to N toggling state when the edge is crossed


The time complexity is down to \$O(N + R\log R)\$, including output (took less than 2 seconds on my system).