Impossible Queries

0

0 votes
Medium, bits
Problem

I have got some impossible queries for you! (or are they? ;) )

You have n binary numbers of length m. The ith binary number is Bi. Also, you have to perform q queries on them. The indexing is zero-based and the indexing of bits starts from left.

The queries are of type : a i j. If a is:

  • 0 : perform Logical AND operation between Bi and Bj and output number of 1s in the result.
  • 1 : perform Logical OR operation between Bi and Bj and output number of 1s in the result.
  • 2 : perform Logical XOR operation between Bi and Bj and output number of 1s in the result.
  • 3 : flip the value of the jth bit of Bi, i.e, make the bit 0 if it is 1 and vice-versa.

Note : For queries of type 0, 1, and 2, the binary numbers remain unchanged.

It is also recommmended to use Fast I/O for C++ and JAVA programmers.

Input Format

  • First line contains Integers n and m
  • The next n lines contains binary numbers of length m. The ith line contains binary number Bi
  • The next line contains an integer q
  • The next q lines contain queries of type : a i j.

Output Format

  • Output number of 1s in the result of type 0, 1 and 2 queries.

Constraints

1n,m2500

0a3

0i<n

0j<m

1q106 (As usual i have kept a few 'easy' test cases to boost your confidence, but try to get 100 points! :) )

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

After the first query, the 0th binary number gets changed to : 11

In the second query, the xor operation between 11 and 01 is 10. This string contains a single 1.

In the third query, the and operation between 11 and 01 is 01. This string contains a single 1.

Editor Image

?