Genomic Pairing Analysis

Time limit: 5s Memory limit: 1024MB Input: Output:

In the cutting-edge research lab at Helix Institute of Molecular Biology, scientists are analyzing strands of DNA to understand how nucleotides pair under spatial constraints.

You are part of a bioinformatics team tasked with analyzing a DNA sequence represented as a string of length NN, composed of the nucleotides:

  • Adenine (AA)
  • Thymine (TT)
  • Cytosine (CC)
  • Guanine (GG)

As per Watson-Crick base pairing rules, AA pairs with TT, and CC pairs with GG.

DNA chemical structure..\text{DNA chemical structure.}.

Task

You are given a string of length NN, made up of characters AA, TT, CC and GG. We define the distance between the characters at positions ii and jj as being ij\left| i-j \right|. You are also given QQ queries of the form l rl\ r, where you have to count the number of AT/CGAT/CG pairs, such that they are at a distance between ll and rr in the string.

Input data

The input file consists of:

  • a line containing integers NN, QQ.
  • a line containing the NN character string SS.
  • QQ lines, the jj-th of which consisting of the 22 integers l,rl, r.

Output data

The output file must contain the answer for each query on a separate line.

Constraints and clarifications

  • 1N1 000 0001 \le N \le 1 \ 000 \ 000.
  • 1Q1 000 0001 \le Q \le 1 \ 000 \ 000.
  • Si{A,T,C,G}S_{i} \in \{A, T, C, G\}.
  • 1lr<N1 \le l \le r < N for each query.
  • TATA and GCGC are considered valid pairs.
# Score Constraints
1 0 Examples
2 10 N50,Q50N \le 50, Q \le 50
3 5 N100,Q100N \le 100, Q \le 100
4 15 N1 000,Q1 000N \le 1 \ 000, Q \le 1 \ 000
5 10 N30 000,Q30 000N \le 30 \ 000, Q \le 30 \ 000
6 15 N100 000,Q100 000N \le 100 \ 000, Q \le 100 \ 000
7 45 No additional restrictions

Example

stdin

8 8
ATCGCGAT
1 1
2 2
3 3
4 4
5 5
6 6
7 7
1 7

stdout

5
0
1
0
1
0
1
8

Explanation

  • The valid pairs of distance 11 are the following: {(0,1),(2,3),(3,4),(4,5),(6,7)}\{(0, 1), (2, 3), (3, 4), (4, 5), (6, 7)\}.
  • The valid pairs of distance 22 are the following: \emptyset.
  • The valid pairs of distance 33 are the following: {(2,5)}\{(2, 5)\}.
  • The valid pairs of distance 44 are the following: \emptyset.
  • The valid pairs of distance 55 are the following: {(1,6)}\{(1, 6)\}.
  • The valid pairs of distance 66 are the following: \emptyset.
  • The valid pairs of distance 77 are the following: {(0,7)}\{(0, 7)\}.

Log in or sign up to be able to send submissions!