Problem:


Score : 300 points

Problem Statement

You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries:

Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending at index r_i (both inclusive). In this string, how many times does AC occurs as a substring?

Notes

A substring of a string T is a string obtained by removing zero or more characters from the beginning and the end of T.

For example, the substrings of ATCODER include TCO, AT, CODER, ATCODER and  (the empty string), but not AC.

Constraints

2 \leq N \leq 10^5

1 \leq Q \leq 10^5

S is a string of length N.

Each character in S is A, C, G or T.

1 \leq l_i < r_i \leq N

Input

Input is given from Standard Input in the following format:

N Q
S
l_1 r_1
:
l_Q r_Q

Output

Print Q lines. The i-th line should contain the answer to the i-th query.

Sample Input 1

8 3
ACACTACG
3 7
2 3
1 8

Sample Output 1

2
0
3

Query 1: the substring of S starting at index 3 and ending at index 7 is ACTAC. In this string, AC occurs twice as a substring.

Query 2: the substring of S starting at index 2 and ending at index 3 is CA. In this string, AC occurs zero times as a substring.

Query 3: the substring of S starting at index 1 and ending at index 8 is ACACTACG. In this string, AC occurs three times as a substring.



Sample input:
8 3
ACACTACG
3 7
2 3
1 8


Sample output:
2
0
3

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

for l, r in lr:
    a = S[l-1:r]
    print(a.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    start, end = map(int, input().split())
    print(S.count('AC', start - 1, end))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
k = 0
cnt = [0 for _ in range(n)]
for i in range(n):
    cnt[i] = s[:i+1].count('AC')

while True:
    l, r = map(int, input().split())
    print(cnt[r-1]-cnt[l-1])
    k += 1
    if q <= k:
        break

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
k = 0
while True:
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))
    k += 1
    if q <= k:
        break

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

for _ in range(q):
    l,r = map(int, input().split())
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
s = input().rstrip().split(' ')
num = int(s[1])
moji = str(input())
for i in range(num):
  t = input().rstrip().split(' ')
  start = int(t[0])
  end = int(t[1])
  print(moji.count("AC", start-1, end))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
mark = [0]*(n-1)
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    mark[i] = 1
for i in range(q):
  l,r = map(int,input().split())
  l -= 1
  r -= 1
  print(sum(mark[l:r]))

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    S = iss()
    ret = [0] * N
    for n in range(N - 1):
        if S[n] == 'A' and S[n + 1] == 'C':
            ret[n] += 1

    for _ in range(Q):
        l, r = il()
        print(sum(ret[l - 1:r])-sum(ret[r-1:r]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    S = iss()
    for _ in range(Q):
        l, r = il()
        print(S[l - 1:r].count('AC'))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    S = iss()
    LR = [il() for _ in range(Q)]
    for lr in LR:
        l, r = lr
        print(S[l - 1:r].count('AC'))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
s=input()
A=[]
for i in range(N-1):
  if s[i]+s[i+1]=="AC":
    A.append(1)
  else:
    A.append(0)
for i in range(Q):
  l,r=map(int,input().split())
  print(sum(A[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
s=input()
for i in range(Q):
  l,r=map(int,input().split())
  print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n,q = map(int, input().split())
    s = input()
    num = [0]*n
    for i in range(n):
        if i > 0:
            if s[i-1] == "A" and s[i] == "C":
                num[i-1] = 1
                num[i] = 1
    for i in range(q):
        l,r = map(int, input().split())
        test = sum(num[l-1: r])
        if (l-1) != 0:
            if s[l-1] != "A":
                test -= 1
        if r != n:
            if s[r-1] != "C":
                test -= 1
        print(test//2)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
Query = [list(map(int,input().split())) for _ in range(q)]
x = [0]
for i in range(n):
    if s[i:i+2] == "AC":
        x.append(1)
    else:
        x.append(0)
for l,r in Query:
    tmp = x[l:r]
    print(tmp.count(1))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]
s1=len(list(s))
l=[0]*(s1-1)
for i in range(s1):
    if s[i:i+2]=='AC':
        l[i]+=1
for j in range(q):
    print( sum( l [lr[j][0]-1:lr[j][1]-1] ))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
#print(n,q)
s = input()
#print(s)

for i in range(q):
	count =0
	l,r = map(int, input().split())
#	print(l,r)
	for i in range(l-1, r-1):
		if s[i]=="A" and s[i+1]=="C":
			count = count + 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(e) for e in input().split()]
s = input()
ac = []
for i in range(n-1):
    if s[i:i+2] == 'AC':
        ac.append(i)
for i in range(q):
    l, r = [int(e) for e in input().split()]
    c = 0
    for j in range(l, r):
        if j-1 in ac:
            c += 1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
s_num = []
sa = []
for i in range(len(s)):
  if s[i] == "T" or s[i] == "G":
    s_num.append(100)
  elif s[i] == "A":
    s_num.append(0)
  elif s[i] == "C":
    s_num.append(1)
    
for j in range(1,len(s)):
  if s_num[j] - s_num[j-1] == 1:
    sa.append(True)
  else:
    sa.append(False)
    
for m in range(q):
  l,r = map(int,input().split())
  target  = sa[l-1:r-1]
  print(target.count(True))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
import re
for l, r in lr:
    s_ = s[l - 1 : r]
    ans = len(re.findall('AC', s_))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
sl = len(s)
ac_cnts = []
for i in range(1, sl+1):
    ac_cnts.append(len(s[:i].split('AC'))-1)
for i in range(q):
    l, r = map(int, input().split())
    print(ac_cnts[r-1]-ac_cnts[l-1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    print(len(s[l-1:r].split('AC'))-1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, q = map(int, readline().split())
s = readline().rstrip()
for _ in range(q):
	l, r = map(int, readline().split())
	l -= 1
	r -= 1
	ans = 0
	for i in range(l, r):
		if s[i] == 'A' and s[i + 1] == 'C':
			ans += 1
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
res = []
for i in range(q):
    l,r = map(int,input().split())
    res.append(S[l-1:r].count('AC'))
for i in res:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
S = input()
L = []
R = []
for i in range(q):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
for i in range(q):    
    print(S[L[i]-1:R[i]].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
anslist = []

for i in range(q):
  l,r = map(int,input().split())
  anslist.append(s[l-1:r])
for i in range(q):
  cnt = 0
  for j in range(len(anslist[i])-1):
    if anslist[i][j] == 'A' and anslist[i][j+1] == 'C':
      cnt += 1 
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q  = map(int, input().split())
S = list(input())
ans = [0] * Q
A = 0

for i in range(Q):
  L, R = map(int, input().split())
  A = 0
  SS = S[L-1:R]
  for j in range(len(SS)-1):
    if SS[j] == "A" and SS[j+1] == "C":
      A += 1
  ans[i] = A

for i in range(Q):
  print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
lr=[list(map(int,input().split())) for _ in range(Q)]

for i in range(Q):
  s=S[lr[i][0]-1 : lr[i][1]]
  print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

box = []
for i in range(N):
    box.append(S[:i+1].count("AC"))

for i, j in lr:
    print(box[j-1] - box[i-1])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(S[l-1:r].count('AC'))

print('\n'.join(list(map(str, ans))))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()

for _ in range(Q):
    l, r = map(int, input().split())
    temp_S = S[l-1:r]
    print(temp_S.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
def main():
    import re

    n, q, s, *lr = open(0).read().split()
    *l, =  map(int, lr[::2])
    *r, = map(int, lr[1::2])
    n = int(n)
    memo = [[None for _ in range(n + 1)] for _ in range(n + 1)]
    for i, j in zip(l, r):
        if memo[i][j] is not None:
            print(memo[i][j])
        else:
            m = re.findall('AC', s[i - 1:j])
            memo[i][j] = len(m)
            print(len(m))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
S = [c for c in S]
total = [0]*N
cnt = 0

flag = False
for i in range(N):
    if flag:
        if S[i]=='C':
            cnt += 1
        flag = False
    else:
        if S[i]=='A':
            flag = True
    total[i] = cnt

for _ in range(Q):
    l, r = map(int, input().split())
    s = total[l-1:r]
    print(s[-1]-s[0])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
# cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = S[:r].count('AC') - S[:l].count('AC')
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
cnt = [S[:i].count('AC') for i in range(1, len(S) + 1)]
# print('cnt', cnt)
for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
m=len(s)-1
idx=[0 for i in range(m)]

for i in range(m):
    if s[i]=="A" and s[i+1]=="C":idx[i]=1
ans=[]
for i in range(q):
    l,r=map(int,input().split())
    ans.append(sum(idx[l-1:r-1]))

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n,Q=map(int,input().split())
s=input()

for i in range(Q):
    l,r=map(int,input().split())
    q=s[l-1:r]
    print(q.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import sys

readline = sys.stdin.readline
n, q = map(int, readline().split())
s = readline().rstrip()
ac = [False] * (n - 1)
for i, x in enumerate(zip(s, s[1:])):
    if x == ('A', 'C'):
        ac[i] = True
for _ in range(q):
    l, r = map(int, readline().split())
    print(sum(ac[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = list(input())
ques = []
for i in range(Q):
    l,r = map(int,input().split())
    ques.append((l,r))

for i in ques:
    tmp = S[i[0]-1:i[1]]
    tmp_s = ''.join(tmp)
    print(tmp_s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for _ in range(q):
  l,r=map(int,input().split())
  print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[]

for i in range(N-1):
  if S[i:i+2]=="AC":
    AC.append(1)
  else:
    AC.append(0)

for i in range(Q):
  print(sum(AC[lr[i][0]-1:lr[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[0 for i in range(N)]

for i in range(N-1):
  if S[i:i+2]=="AC":
    AC[i]=1
    i=i+1

for i in range(Q):
  print(sum(AC[lr[i][0]-1:lr[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[0 for i in range(N)]

for i in range(N-1):
  if S[i:i+2]=="AC":
    AC[i]=1

for i in range(Q):
  print(sum(AC[lr[i][0]-1:lr[i][1]-1]))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for _ in range(q)]

for i in lr:
  cnt = 0
  ss = s[i[0] - 1:i[1]]
  for j in range(len(ss)-1):
    if (ss[j] == 'A') and (ss[j+1] == 'C'):
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
    counter = 0
    l, r = map(int,input().split())
    for i in range(r - l):
        if s[i + l - 1] + s[i + l] == "AC":
            counter += 1
    ans.append(counter)
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
count = [0]*q
for i in range(q):
    l, r = map(int,input().split())
    str = s[l - 1: r]
    counter = 0
    for n in range(len(str) - 1):
        if str[n] + str[n + 1] == "AC":
            count[i] += 1
for i in count:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
    l, r = map(int,input().split())
    str = s[l - 1: r]
    counter = 0
    for n in range(len(str) - 1):
        if str[n] + str[n + 1] == "AC":
            counter += 1
    ans.append(counter)
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S=input()
lr=[]
for _ in range(Q):
    lr.append(tuple(map(int, input().split())))
#print(N, Q, S, lr)

ACs=[m.start()+1 for m in re.finditer('AC', S)]
#print(ACs)

for val in lr:
    OK=[strt for strt in ACs if val[0] <= strt and strt + 1 <= val[1]]
    print(len(OK))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()

for i in range(Q):
    l,r = map(int,input().split())
    ans = S[l-1:r].count('AC')
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for _ in range(q):
  l,r=map(int,input().split())
  word=s[l-1:r]
  print(word.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

csum = [0]
rcsum = [0]
for i in range(n):
    csum.append(s[i:n].count('AC'))
    #rcsum.append(s[n-i:n].count('AC'))


# print(csum)
# print(rcsum)

for _ in range(q):
    l, r = map(int, input().split())
    print(csum[l]-csum[r])
    #print('回答：', csum[l], rcsum[n-r])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

csum = [0]
rcsum = [0]
for i in range(n):
    csum.append(s[i:n].count('AC'))
    rcsum.append(s[n-i:n].count('AC'))


# print(csum)
# print(rcsum)

for _ in range(q):
    l, r = map(int, input().split())
    print(csum[l]-csum[r])
    #print('回答：', csum[l], rcsum[n-r])

Submission status: Time Limit Exceeded

Solution code:
import re


n, q = map(int, input().split())
s = input()
lis = [x.span() for x in re.finditer("AC", s)]
for i in range(q):
    l, r = map(int, input().split())
    cnt = 0
    for j in lis:
        if l-1 <= j[0] and j[1] <= r:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
for i in range(q):
    a,b = map(int,input().split())
    print(s.count("AC",a-1,b))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

# s = "AACACTTTTAC"
# print(s.count("AC"))#3

lr=[]
s2 = ""
n, q = map(int, input().split())
s = input()
for i in range(q):
        l,r = map(int, input().split())
        lr.append([l,r])

for i in range(q):
        s2 = s[lr[i][0] - 1:lr[i][1]]
        # print(s2)
        print(s2.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [None] * Q
for _ in range(Q):
    lr[_] = list(map(int, input().split()))
for _ in range(Q):
    ans = S.count("AC", lr[_][0] - 1, lr[_][1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
lr = [None] * Q
for _ in range(Q):
    lr[_] = list(map(int, input().split()))
for _ in range(Q):
    ans = S[lr[_][0] - 1:lr[_][1]].count("AC")
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

for _ in range(q):
    li, ri = map(int, input().split())
    print(s[li - 1:ri].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
N, Q = list(map(int, input().split()))
S = input()

flags = [0] * N
for i in range(N):
    if i != 0 and S[i - 1:i + 1] == 'AC':
        flags[i] = 1
acc_sum = [sum(flags[:i+1]) for i in range(N)]

for i in range(Q):
    l, r = list(map(int, input().split()))
    if l == r:
        print(0)
    else:
        print(acc_sum[r - 1] - acc_sum[l - 1])

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for i in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split()) 
q=input() 
l=[list(map(int,input().split())) for _ in range(m)] 
for j in range(m): 
	cnt=0 
	for i in range(l[j][0],l[j][1]): 
		if (q[i-1]+q[i])=="AC": 
			cnt+=1 
	print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    N,Q=map(int,input().split())
    S=str(input())

    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())
        L[i], R[i] = L[i]-1, R[i]-1

    where=[]

    for i in range(N-1):
        if S[i:i+2]=='AC':
            where.append(i)

    for j in range(Q):
        cnt=0
        for i in where:
            if L[j]<=i and i+1<=R[j]:
                cnt+=1
        print(cnt)


resolve()

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
A = []
B = []
for i in range(Q):
  l,r = map(int,input().split())
  A.append((l-1,r))
for i in range(len(S)-1):
  if S[i:i+2] == 'AC':
    B.append((i,i+2))
for el in A:
  res = 0
  a,b = el
  for el in B:
    x,y = el
    if a <= x and y <= b:
      res += 1
  print(res)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N)

last = S[0]
for i in range(1, N):
    c = S[i]
    if (last + c) == 'AC':
        cnt[i] = 1
    last = c

for _ in range(Q):
    l, r = map(int, input().split())
    ans = sum(cnt[l:r])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N - 1)

for i in range(N - 1):
    if S[i] + S[i + 1] == 'AC':
        cnt[i] = 1

for _ in range(Q):
    l, r = map(int, input().split())
    ans = sum(cnt[l - 1:r - 1])
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
A = []
B = []
for i in range(Q):
  l,r = map(int,input().split())
  A.append((l-1,r-1))
for el in A:
  res = 0
  m,n = el
  i = 0
  while True:
    if m + i + 2 > n+1:
      break
    if S[m+i:m+i+2] == 'AC':
      res += 1
    i += 1    
  print(res)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
for _ in range(Q):
    ans = 0
    l, r = map(int, input().split())
    sub = S[l - 1: r]
    print(sub.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(str(input()))


for i in range(q):
    l, r = map(int,input().split())
    subs = s[l-1:r]
    subs = ''.join(subs)
    print(subs.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
L = [0 for _ in range(n)]

for i in range(n - 1):
    if s[i:i + 2] == "AC":
        L[i + 1] = 1
        i += 1

for i in range(q):
    l, r = map(int, input().split())
    print(sum(L[l:r]))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

def counter(L, R):
    c = 0
    for i in range(L, R):
        if s[i:i + 2] == "AC":
            c += 1
            i +=1
    return c

for i in range(q):
    l, r = map(int, input().split())
    print(counter(l - 1, r - 1))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

def counter(L, R):
    c = 0
    for i in range(L, R):
        if s[i:i + 2] == "AC":
            c += 1
    return c

for i in range(q):
    l, r = map(int, input().split())
    print(counter(l - 1, r - 1))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S  = input()
for i in range(Q):
    l,r = map(int,input().split())
    s = S[l-1:r]
    print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=list(input())
t=[0]*n
for i in range(n-1):
    if s[i]+s[i+1]=="AC":
        t[i]=1
for i in range(q):
    l,r=map(int,input().split())
    print(sum(t[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
count = 0
for _ in range(Q):
    l,r = map(int,input().split())
    l-=1
    r-=1
    for i in range(l,r):
        if S[i] == "A" and S[i+1] == "C":
            count += 1
    print(count)
    count = 0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
list_s = list(s)
list_score = [ list(map(int,input().split(" "))) for i in range(q)]
list_c = []
for i in range(n-1):
    if list_s[i] == "A" and list_s[i+1] == "C":
        list_c.append(1)
    else:
        list_c.append(0)

for i in range(q):
    g = list_score[i]
    print(sum(list_c[g[0]-1:g[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
list_s = list(s)
list_score = [ list(map(int,input().split(" "))) for i in range(q)]
list_c = []
for i in range(n-1):
    if list_s[i] == "A" and list_s[i+1] == "C":
        list_c.append([i+1, i+2])


ans = 0

for i in range(q):
    g = list_score[i]
    ans = 0
    for j in range(len(list_c)):
        f = list_c[j]
        if g[0] <= f[0] and f[1] <= g[1]:
            ans += 1

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
list_s = list(s)
list_score = [ list(map(int,input().split(" "))) for i in range(q)]

for i in range(q):
    a = list_score[i]
    b = list_s[a[0]-1:a[1]]
    c = "".join(b)
    print(c.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())

s = input()
l = [0 for _ in range(q)]
r = [0 for _ in range(q)]
for i in range(q):
	l[i],r[i] = map(int,input().split())
for i in range(q):

	a = s[l[i]-1:r[i]]
	#print(a)
	count = 0
	for j in range(len(a)-1):
		if a[j:j+2] =="AC": 
			count += 1
	print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q= map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i] = map(int,input().split())
  cnt=0
  for j in range(l[i]-1,r[i]-1):
    #print(S[j]+S[j+1])
    if S[j]+S[j+1]=="AC":
      cnt +=1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    T = S[l-1:r]
    ans.append(T.count('AC'))
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
ans = []
for i in range(q):
    l,r = map(int,input().split())
    buf = s[max(0,l-1):r]
    ans.append(buf.count('AC'))

for aa in ans:
    print(aa)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, Q = map(int, input().split())
    S = input()
    for _ in range(Q):
        l, r = map(int, input().split())
        cnt = 0
        s = S[l - 1:r]
        for i in range(r - l):
            if s[i:i + 2] == "AC":
                cnt += 1
        print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, Q = map(int, input().split())
    S = input()
    for _ in range(Q):
        l, r = map(int, input().split())
        print(S[l - 1:r].count('AC'))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
for _ in range(q):
    l,r=map(int,input().split())
    print(s[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()

# lr = [list(map(int, input().split())) for _ in range(q)]

# 愚直な計算時間
# ループn回
# リスト切り取りO(n)
# O(n^2)
# 計算リミットが2000msで、n<=10^5
# 0(n)でn=10^6くらいが限度
# O8n^2)だと、n=3000くらい

# 先に回数を数える。累積和的に
hoge = [s[0:(i + 1)].count('AC') for i in range(n)]

for _ in range(q):
    l, r = map(int, input().split())
    print(hoge[r - 1] - hoge[l - 1])

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
lr = [tuple(map(int, input().split())) for _ in range(q)]

# table[i] = i文字目以下のsにACは部分文字列として何回現れるか
table = []
for i in range(n+1):
    table.append(s[:i].count('AC'))

for l, r in lr:
    print(table[r] - table[l])

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

L = []
R = []

for i in range(Q):
    l, r = MAP()
    L.append(l)
    R.append(r)

AC_index = []

for i in range(len(S)-1):
    s = S[i] + S[i+1]
    if s == 'AC':
        AC_index.append(i)

for i in range(Q):
    count = 0
    for j in AC_index:
        if L[i]-1 <= j and R[i]-1 >= j+1:
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

L = []
R = []

for i in range(Q):
    l, r = MAP()
    L.append(l)
    R.append(r)

for i in range(Q):
    bubun_S = S[L[i]-1:R[i]]
    s_list = bubun_S.split('AC')
    print(len(s_list)-1)