#FT0000009. Siêu máy tính bật tắt bit (Supercomputer)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Siêu máy tính bật tắt bit (Supercomputer)
Supercomputer
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A supercomputer contains memory bits, numbered through . Every bit initially equals (off), and each bit can only be or (on).
Process commands in their given order. Command F k flips bit : becomes and becomes . In particular, flipping the same bit twice restores its original state.
Command C l r counts how many bits are currently in the inclusive interval . It counts enabled bits, not the length of the interval. Counting does not change memory; a flip affects all subsequent queries.
Input
- Line 1:
n qgives number of bits and commands. - Next lines: each line contains one of the following commands, in execution order:
F k: flip the bit at position .C l r: count enabled bits from through .
Output
For each C l r command, print one integer: the number of bits equal to in the inclusive interval at that moment.
Subtasks
Subtask 1 (20 points):
- .
- .
- .
- .
- each bit is in .
Subtask 2 (30 points):
- .
- .
- .
- .
- each bit is in .
Subtask 3 (50 points):
- .
- .
- .
- .
- each bit is in .
Examples
Input
5 6
F 1
C 1 5
F 3
C 2 4
F 1
C 1 3
Output
1
1
1
Explanation
There are elements. All bits initially equal .
-
Command 1 —
F 1: Bit flips from to . The bit states become[1, 0, 0, 0, 0]. -
Command 2 —
C 1 5: Bits through are[1, 0, 0, 0, 0]; exactly bits equal , so print1. -
Command 3 —
F 3: Bit flips from to . The bit states become[1, 0, 1, 0, 0]. -
Command 4 —
C 2 4: Bits through are[0, 1, 0]; exactly bits equal , so print1. -
Command 5 —
F 1: Bit flips from to . The bit states become[0, 0, 1, 0, 0]. -
Command 6 —
C 1 3: Bits through are[0, 0, 1]; exactly bits equal , so print1.
Collect the answers to output-producing commands in their input order, printing one answer per line.