PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000009. Siêu máy tính bật tắt bit (Supercomputer)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn memory bits, numbered 11 through nn. Every bit initially equals 00 (off), and each bit can only be 00 or 11 (on).

Process qq commands in their given order. Command F k flips bit kk: 00 becomes 11 and 11 becomes 00. In particular, flipping the same bit twice restores its original state.

Command C l r counts how many bits are currently 11 in the inclusive interval [l,r][l,r]. 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 q gives number of bits and commands.
  • Next qq lines: each line contains one of the following commands, in execution order:
    • F k: flip the bit at position kk.
    • C l r: count enabled bits from ll through rr.

Output

For each C l r command, print one integer: the number of bits equal to 11 in the inclusive interval [l,r][l,r] at that moment.

Subtasks

Subtask 1 (20 points):

  • 1≤n≤241\le n\le 24.
  • 1≤q≤301\le q\le 30.
  • 1≤k≤n1\le k\le n.
  • 1≤l≤r≤n1\le l\le r\le n.
  • each bit is in {0,1}\{0,1\}.

Subtask 2 (30 points):

  • 1≤n≤12001\le n\le 1200.
  • 1≤q≤16001\le q\le 1600.
  • 1≤k≤n1\le k\le n.
  • 1≤l≤r≤n1\le l\le r\le n.
  • each bit is in {0,1}\{0,1\}.

Subtask 3 (50 points):

  • 1≤n≤10000001\le n\le 1000000.
  • 1≤q≤10000001\le q\le 1000000.
  • 1≤k≤n1\le k\le n.
  • 1≤l≤r≤n1\le l\le r\le n.
  • each bit is in {0,1}\{0,1\}.

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 n=5n=5 elements. All bits initially equal 00.

  1. Command 1 — F 1: Bit 11 flips from 00 to 11. The bit states become [1, 0, 0, 0, 0].

  2. Command 2 — C 1 5: Bits 11 through 55 are [1, 0, 0, 0, 0]; exactly 11 bits equal 11, so print 1.

  3. Command 3 — F 3: Bit 33 flips from 00 to 11. The bit states become [1, 0, 1, 0, 0].

  4. Command 4 — C 2 4: Bits 22 through 44 are [0, 1, 0]; exactly 11 bits equal 11, so print 1.

  5. Command 5 — F 1: Bit 11 flips from 11 to 00. The bit states become [0, 0, 1, 0, 0].

  6. Command 6 — C 1 3: Bits 11 through 33 are [0, 0, 1]; exactly 11 bits equal 11, so print 1.

Collect the answers to output-producing commands in their input order, printing one answer per line.