#P3870. [TJOI2009] 开关

    ID: 2803 远端评测题 1000ms 125MiB 尝试: 2 已通过: 1 难度: 6 上传者: 标签>2009线段树各省省选枚举,暴力概率论,统计块状链表,块状数组,分块天津

[TJOI2009] 开关

Description

There are nn lights in a row, numbered from left to right as 1,2,,n1, 2, \ldots, n. Then mm operations are performed in order.

There are two types of operations:

  1. Given an interval [a,b][a, b], flip the state of every light whose index is in this interval (turn on lights that are off, and turn off lights that are on).
  2. Given an interval [a,b][a, b], output how many lights are on within this interval.

All lights are initially off.

Input Format

The first line contains two integers nn and mm, the number of lights and the number of operations, respectively.

Each of the next mm lines contains three integers cc, aa, and bb, where cc denotes the type of operation.

  • If c=0c = 0, it is the first type of operation.
  • If c=1c = 1, it is the second type of operation.

aa and bb are the left and right boundaries of the operation interval, respectively.

Output Format

For each operation of the second type, output one line containing an integer, the number of lights that are on in the queried interval.

4 5
0 1 2
0 2 4
1 2 3
0 2 4
1 1 4

1
2

Hint

Constraints.

For all testdata, it is guaranteed that 2n1052 \le n \le 10^5, 1m1051 \le m \le 10^5, 1a,bn1 \le a, b \le n, and c{0,1}c \in \{0, 1\}.

Translated by ChatGPT 5