QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22345. 切换灯光

Statistics

Farmer John 让奶牛玩益智玩具以保持头脑敏锐。较大的玩具之一是牛棚的灯。$N$ $(2 \le N \le 500)$ 个牛栏方便地编号为 $1,\ldots,N$,每个上方都有一盏彩灯。

晚上开始时,所有灯都关闭。奶牛用 $N$ 个按钮开关控制灯;按下开关 $i$ 会把灯 $i$ 从关变开或从开变关。

奶牛读取并执行 $M$ $(1 \le M \le 2,000)$ 个操作,每个由两个整数值之一表示 $(0 \le operation \le 1)$。

第一种操作(命令 0)后有两个整数 $S_{i}$ 和 $E_{i}$ $(1 \le S_{i} \le E_{i} \le N)$,指定起止开关。奶牛将从 $S_{i}$ 到 $E_{i}$(含两端)的每个按钮恰好按一次。

第二种操作(命令 1)要求统计两个整数 $S_{i}$ 和 $E_{i}$ $(1 \le S_{i} \le E_{i} \le N)$ 指定的闭区间中有多少灯亮着。

处理操作列表并给出正确的计数,帮助 FJ 确保奶牛得到正确答案。

输入格式

  • 第 1 行:两个空格分隔的整数 $N$ 和 $M$。
  • 第 $2,\ldots,M+1$ 行:每行用三个空格分隔的整数 operation、$S_{i}$、$E_{i}$ 表示一个操作。

输出格式

  • 第 $1,\ldots,number$ 个查询对应的行:每个输出查询的计数作为单独一个整数,占一行。

样例

输入格式 1

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

输出格式 1

1
2

说明

四盏灯,五条命令。应处理的序列如下:

            灯
            1 2 3 4
  初始:     O O O O   O = 关  * = 开
  0 1 2 ->  * * O O  切换灯 1 和 2
  0 2 4 ->  * O * *
  1 2 3 ->  1        统计区间 2..3 中亮灯的数量
  0 2 4 ->  * * O O  切换灯 2、3、4
  1 1 4 ->  2        统计区间 1..4 中亮灯的数量

题目作者:LongFan,2008

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.