QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#22345. 전등 전환

統計

Farmer John은 지능 장난감을 주어 소들의 사고력을 유지한다. 큰 장난감 중 하나는 헛간 전등이다. 편리하게 $1,\ldots,N$번인 $N$ $(2 \le N \le 500)$개의 우리 위마다 색 전등이 있다.

저녁 시작에는 모두 꺼져 있다. 소는 $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.