Bitsets
Time limit3sMemory limit2048 MB
Count the columns where the bits in rows l through r are all equal, with each query's l and r generated online from the previous answers.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Prefix sum, String
- Solved
- No attempts yet
Problem
Consider the following operations on bitsets of size :
- : if both and are 1. Otherwise, .
- : if at least one of and is 1. Otherwise, .
- : if exactly one of and is 1. Otherwise, .
- : if is 0. Otherwise, .
You are given an array of bitsets . Write a program that answers queries of the following form:
- Read two integers and .
- Compute the bitset .
- Count the number of ones in . This count is the answer.
Input
The first line contains two integers and (; ). Each of the following lines contains a bitset of characters, each 0 or 1.
The next line contains the number of queries (). The following line contains three integers , , and ().
The queries are generated from , , and the answers to the previous queries. Define the sequences and as follows:
- .
- .
- For , .
- For , .
For query , let and .
Output
Output a single integer: the sum of the answers to all queries.
Hint
The queries are listed below: