#P3870. Toggle and Query Lights
Toggle and Query Lights
Toggle and Query Lights
You are given n lights arranged in a row and numbered from 1 to n. Initially, all lights are off. You need to perform m operations sequentially. There are two types of operations:
- Type 1: Given an interval [a, b], toggle the state of each light in the interval (i.e. turn on a light if it is off, and turn it off if it is on).
- Type 2: Given an interval [a, b], output the number of lights that are on in that interval.
The operations use the following format. The operation is represented by an integer, with 1 for toggle and 2 for query. All intervals are given using 1-indexing.
Note: In formulas, let \(n\) denote the number of lights and \(m\) denote the number of operations.
inputFormat
The first line contains two integers \(n\) and \(m\) representing the number of lights and the number of operations, respectively.
Each of the following \(m\) lines contains three integers \(op, a, b\) where \(op\) is the type of operation. If \(op = 1\), then perform toggle on the interval [a, b]. If \(op = 2\), then output the number of lights that are on in the interval [a, b].
outputFormat
For each operation of type 2, print the number of lights that are on in the specified interval. Each answer should be printed on its own line.
sample
5 3
1 1 3
2 2 4
2 1 5
2
3
</p>