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

#SRD0000152. Tập con bit (Subset of Bits)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tập con bit (Subset of Bits)

Subset of Bits

Source: VNOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Initially you have an empty multiset of nonnegative integers. Process qq operations; duplicate copies are allowed and counted individually:

  • add s: insert one copy of ss.
  • del s: remove exactly one copy of ss, guaranteed to exist at the time of removal.
  • cnt s: count the current copies of values aa satisfying bitwise aANDs=aa\mathbin{\mathrm{AND}}s=a.

Equivalently, every set bit of aa must also be set in ss.

Input

  • The first line contains positive integer qq.
  • Each of the next qq lines contains an operation keyword add, del, or cnt, followed by integer ss.

Output

For each cnt query print the number of currently stored copies satisfying aANDs=aa\mathbin{\mathrm{AND}}s=a. Insertions and deletions have no output.

Subtasks

  • Subtask 1 (20 points): 1≤q≤1001\le q\le 100; 0≤s≤2160\le s\le2^{16}; every del s removes an existing copy.
  • Subtask 2 (30 points): 1≤q≤50001\le q\le 5000; 0≤s≤2160\le s\le2^{16}; every del s removes an existing copy.
  • Subtask 3 (50 points): 1≤q≤2000001\le q\le 200000; 0≤s≤2160\le s\le2^{16}; every del s removes an existing copy.

Examples

Example 1

Input

7
add 11
cnt 15
add 4
add 0
cnt 6
del 4
cnt 15

Output

1
2
2

Explanation

After adding 1111, cnt 15 counts it since 11AND15=1111\mathbin{\mathrm{AND}}15=11: answer 11. After inserting 44 and 00, cnt 6 counts 44 and 00 but not 1111, hence 22. Deleting 44 leaves 1111 and 00, both submasks of 1515, hence $2.