#K9346. Bitwise Permission Operations

    ID: 38424 Type: Default 1000ms 256MiB

Bitwise Permission Operations

Bitwise Permission Operations

You are given a series of operations to manage permission bits in an integer. In this problem, permissions are represented as bits in a 32-bit non-negative integer. Initially, the permission value is 0. You need to perform three types of operations:

  • add p: Set the p-th bit (i.e., perform the operation \(currentPerms = currentPerms \;|\; (1 \ll p)\)).
  • remove p: Clear the p-th bit (i.e., perform the operation \(currentPerms = currentPerms \;\&\; \sim(1 \ll p)\)).
  • check p: Check whether the p-th bit is set. Print 1 if \(currentPerms \;\&\; (1 \ll p) \neq 0\) and 0 otherwise.

The input starts with the number of operations that will be provided. Process the operations sequentially, maintaining an updated permission value, and output the result of each check operation on a new line.

inputFormat

The first line contains an integer (Q), representing the number of operations. Each of the following (Q) lines contains an operation in the format:

operation p

Where operation is one of add, remove, or check, and (p) is a non-negative integer representing the bit position (0-indexed).

For example:

4
add 1
add 3
check 1
check 3

outputFormat

For each check operation, output a single line containing the result: 1 if the corresponding bit is set, and 0 otherwise. There is no output for add or remove operations.## sample

4
add 1
add 3
check 1
check 3
1

1

</p>