Mutating DNA

아직 제출이 없습니다시간 제한1초메모리 제한2048 MB

문제

Grace is a biologist working in a bioinformatics firm in Singapore. As part of her job, she analyses the DNA sequences of various organisms. A DNA sequence is defined as a string consisting of characters "A", "T", and "C". Note that in this task DNA sequences do not contain character "G".

We define a mutation to be an operation on a DNA sequence where two elements of the sequence are swapped. For example a single mutation can transform "ACTA" into "AATC" by swapping the highlighted characters "A" and "C".

The mutation distance between two sequences is the minimum number of mutations required to transform one sequence into the other, or 1-1 if it is not possible to transform one sequence into the other by using mutations.

Grace is analysing two DNA sequences aa and bb, both consisting of nn elements with indices from 00 to n1n - 1. Your task is to help Grace answer qq questions of the form: what is the mutation distance between the substring a\[x..y]a\[x..y] and the substring b\[x..y]b\[x..y]? Here, a substring s\[x..y]s\[x..y] of a DNA sequence ss is defined to be a sequence of consecutive characters of s, whose indices are xx to yy inclusive. In other words, s\[x..y]s\[x..y] is the sequence s\[x]s\[x+1]s\[y]s\[x]s\[x + 1] \dots s\[y].

제한

  • 1 n,q 100,0001 \le n, q \le 100\\,000
  • 0xyn10 \le x \le y \le n - 1
  • Each character of aa and bb is one of "A", "T", and "C".