Power of 3

Given a binary string A of size N and an integer matrix B of size Q x 3.

Matrix B had Q queries:

  1. For queries of type B[i][0] = 1, flip the value at index B[i][1] in A if and only if the value at that index is 0 and return -1.
  2. For queries of type B[i][0] = 0, Return the value of the binary string from index B[i][1] to B[i][2] modulo 3.

Note: Rows are numbered from top to bottom and columns are numbered from left to right.



Input Format

The first argument given is the string A.
The second argument given is the integer matrix B.

Output Format

Return an array of size Q where ith value is answer to ith query.

Constraints

1 <= N <= 100000
1 <= Q <= 200000
1 <= B[i][1], B[i][2] <= N
B[i][1] <= B[i][2]

For Example

Input 1:
    A = 10010
    B = [ [0, 3, 5]
          [0, 3, 4]
          [1, 2, -1]
          [0, 1, 5]
          [1, 2, -1]
          [0, 1, 4] ]
Output 1:
    [2, 1, -1, 2, -1, 1]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Power of 3 on Interview Code Editor
Sign Up
to access hints and editorial solutions for Power of 3

Discussion


Loading...
Click here to start solving coding interview questions