Hamming distance queries
InterviewTime limit6sMemory limit512 MB
Given binary strings a and b, answer queries asking for the Hamming distance between a substring of a and a substring of b.
- Level
Medium5 of 10
- Topics
- Prefix sum, String, Array, Bit manipulation
- Solved
- No attempts yet
Problem
The Hamming distance between two binary strings and of equal length is the number of positions where the two values differ. For example, the Hamming distance between "00111" and "10101" is 2.
You are given binary strings and . Write a program that answers the following query.
p1 p2 len: print the Hamming distance between the substrings and .
String indices start at 0.
Input
The first line has the binary string and the second line has the binary string . The length of each string is a positive integer at most 200,000.
The third line has the number of queries (). Each of the next lines has one query as , , and separated by spaces (, , ).
Output
Print the answer to each query on its own line, in the order the queries are given.