#P2846. Barn Lights

    ID: 16104 Type: Default 1000ms 256MiB

Barn Lights

Barn Lights

Farmer John lets the cows play with intellectual toys. One of the larger toys is the lights in the barn. There are $$N$$ cow stalls numbered from $$1$$ to $$N$$, each with a light that is initially off. The cows control the lights with a set of pushbutton switches. Pushing switch $$i$$ toggles the state of light $$i$$ (from off to on or on to off).

A list of $$M$$ operations is executed. Each operation is one of two types:

  • Toggle Operation (0 S E): For a given range $$[S, E]$$, toggle each light in that interval.
  • Query Operation (1 S E): For a given range $$[S, E]$$, count how many lights are on.

Process the list of operations and for each query, output the correct count.

Constraints:

  • $$2 \le N \le 10^5$$
  • $$1 \le M \le 10^5$$
  • For each operation, $$1 \le S \le E \le N$$

inputFormat

The first line contains two integers $$N$$ and $$M$$, representing the number of cow stalls and the number of operations.

The following $$M$$ lines each contain an operation in one of the following formats:

  • 0 S E: Toggle all lights in the range $$[S, E]$$.
  • 1 S E: Query how many lights are on in the range $$[S, E]$$.

outputFormat

For each query operation (operation type 1), output a single line containing the count of lights that are on in the specified range.

sample

4 7
0 1 2
1 1 4
0 2 4
1 2 3
0 1 4
1 1 1
1 1 4
2

1 0 1

</p>