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:
import numpy as np
N,Q = map(int, input().split())

S = str(input())
l = np.empty(Q)
r = np.empty(Q)
for i in range (Q):
    l[i],r[i] = map(int, input().split())
for i in range (Q):
    a = int(l[i]-1)
    b = int(r[i])
    s2 = S[a:b-1]
    s3 = S[a+1:b]
    #print(s2)
    #print(s3)
    S2 = list(s2.replace('A','1').replace('C','0').replace('G','0').replace('T','0'))

    nps2 =  np.array(S2).astype(int)

    S3 = list(s3.replace('A','0').replace('C','1').replace('G','0').replace('T','0'))
    nps3 =  np.array(S3).astype(int)


    SS = (nps2*nps3).sum()


    print(SS)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
l_r = []
for i in range(Q):
    l_r.append(list(map(int, input().split())))
    print(S[l_r[i][0]-1: l_r[i][1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N , Q = map(int , input().split())
S = input()
l = []
r = []

for q in range(Q):
	a ,b = map(int , input().split())
	l.append(a)
	r.append(b)

for q in range(Q):
	count = 0
	a = l.pop(0)
	b = r.pop(0)
	subS = S[a-1:b]
	while subS!= "":
		x = subS.find("A")
		if x!= -1:
			subS = subS[x:]
		else:
			break
			if subS =="":
				break
		if len(subS) <= 1:
			break
		elif subS[1] == "C":
			count += 1
			subS = subS[2:]
#			print("subS = " + subS)
		else:
			subS = subS[1:]
#			print("subS = " + subS)
		if subS == "":
			break
	print(count)

Submission status: Time Limit Exceeded

Solution code:
#import re

i = int(input().split()[1])
s = input()
k = 0
f = []
e = []
result = []

for k in range(i):
    ff, ee = map(int, input().split())
    f.append(ff)
    e.append(ee)
    #result.append(s[ft - 1:et].count("AC"))
    #result.append(len(re.findall("AC", s[ft - 1:et])))

for k in range(i):
    print(s[f[k] - 1:e[k]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q=[int(_) for _ in input().split()]
S=list(input())
hani=[[int(a) for a in input().split()] for j in range(Q)]
ACindex=[S[i]=="A" and S[i+1]=="C" for i in range(N-1)]
for j in hani:
    print(sum(ACindex[j[0]-1:j[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
#import re

i = int(input().split()[1])
s = input()
result = []

for k in range(i):
    ft, et = map(int, input().split())
    result.append(s[ft - 1:et].count("AC"))
    #result.append(len(re.findall("AC", s[ft - 1:et])))

for kekka in result:
    print(kekka)

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, Q = (int(i) for i in input().split())
char = input()
charlist = list(char)
hoge = 0
onon = []
for i in charlist:
    if char[hoge:(hoge + 2)] == "AC":
        onon.append(hoge + 1)
    hoge += 1
    if (hoge - 1) >= int(N):
        break
for i in range(Q):
    l, r = (int(i) for i in input().split())
    result = [i for i in onon if i >= l and i <= (r - 1)]
    left = bisect.bisect_left(onon,l)
    right = bisect.bisect_left(onon,r)
    print(right - left)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
L = []
R = []
# ans = []
for _ in range(Q):
	l, r = map(int, input().split())
	L.append(l)
	R.append(r)
flag = [0, 0]
for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		flag.append(1)
	else:
		flag.append(0)
# print(flag)
ans = [[0 for i in range(N+1)] for j in range(N+1)]
for i in range(N):
	for j in range(1,N+1):
		ans.append(0)
		
for i in range(N):
	for j in range(i,N):
		ans[i][j+1] = ans[i][j] + flag[j+1]
		ans[i+1][j] = ans[i][j] - flag[i+1]

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, sys.stdin.readline().split())
S = sys.stdin.readline()
AC = 'AC'

ans = []
for i in range(Q):
    l, r = map(int, sys.stdin.readline().split())
    ans.append(S[max(l - 1, 0):r].count(AC))

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

starts = [0 for k in range(q)]
ends = [0 for k in range(q)]
for i in range(q):
    starts[i], ends[i] = map(int, input().split())

target = 'AC'
index = -1
astrs = []
while True:
    index = s.find(target, index + 1)
    if index == -1:
        break
    else:
        astrs.append(index+1)

for i in range(q):
    ans = [x for x in astrs if x in range(starts[i], ends[i])]
    print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int,input().split()))
s = list(input())
num = list()
check = [0]*n
for i in range(0,n-1):
    if s[i] == "A" and s[i+1] == "C":
        check[i] = 1
for i in range(0,q):
    num.append(list(map(int,input().split())))
    print(len([k for k in range(num[i][0]-1,num[i][1]-1) if check[k] == 1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(x) for x in input().split())
S = list(input())
count = [0 for i in range(N-1)]
for i in range(N-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            count[i] = 1
            i += 1

for i in range(Q):
    l,r = (int(x) for x in input().split())
    print(sum(count[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
l,r=[],[]
for i in range(Q):
    l0,r0=map(int,input().split())
    l.append(l0)
    r.append(r0)
for i in range(Q):
    c=0
    for j in range(l[i]-1,r[i]-1):
        if (S[j]=='A') and (S[j+1]=='C'):
            c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:

N, Q = map(int, input().split())
S = input()
lrs = [list(map(int, input().split())) for _ in range(Q)]

length = len(lrs)
count = [0] * length
for i in range(len(S) - 1):
    if S[i] != 'A':
        continue
    if S[i+1] != 'C':
        continue
    for j in range(length):
        lrsj = lrs[j]
        if lrsj[0] <= i+1 and i < lrsj[1] and i+1 != lrsj[1]:
            count[j] += 1

for c in count:
    print(c)

Submission status: Time Limit Exceeded

Solution code:
#ACを検索して開始位置をインデックスにしておき、それを操作すれば多少はマシか
import numpy as np
N,Q=[int(_) for _ in input().split()]
S=list(input())
hani=[[int(a) for a in input().split()] for j in range(Q)]
ACindex=[S[i]=="A" and S[i+1]=="C" for i in range(N-1)]
for j in hani:
    print(sum(ACindex[j[0]-1:j[1]-1]))

Submission status: Time Limit Exceeded

Solution code:
inr = lambda: list(map(int, input().split()))
inn = lambda: input()
 
N,Q = inr()
S = inn()
for q in range(Q):
    l,r = inr()
    bubun = S[l-1:r]
    
    bbb = ""
    for b in bubun:
      if b in ["A","C"]:
        bbb += b
    
    print(bbb.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(x) for x in input().split())
S = input()
# print(s.count("AC"))
tmp = []
for i in range(Q):
    a,b = (int(x) for x in input().split())
    tmp.append(S[a-1:b])
    # print(tmp)
for j in range(Q):
    print(tmp[j].count("AC"))

Submission status: Time Limit Exceeded

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

for i in range(Q):
    s_tmp = S[max(lr[i][0] - 1, 0):lr[i][1]]
    s_tmp_aft = S[lr[i][1]:]
    s_tmp_aft_2 = S[lr[i][1] - 1:]
    cnt =s_tmp.count('AC') - max(s_tmp_aft.count('AC'), s_tmp_aft_2.count('AC'))
    if cnt > 0:
        print(cnt)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, Q = map(int, input().split())
s = str(input())
for i in range(0, 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()
 
for i in range(Q):
    l, r = map(int,input().split())
    str = S[l-1:r]
    print(str.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = input()
import re
for _ in range(Q) :
    l, r = map(int,input().split())
    print(len(re.findall("AC",S[l-1:r])))

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

questions = []
for i in range(q):
    questions.append(list(map(int, input().split())))

ac_positions = []
for i in range(n):
    if s[i:i + 2] == 'AC':
        ac_positions.append(i + 1)

for question in questions:
    ac_count = 0

    explore_ac_positions = ac_positions[
                           bisect.bisect_left(ac_positions, question[0]):
                           bisect.bisect_right(ac_positions, question[1])]
    for ac_position in explore_ac_positions:
        if question[0] <= ac_position and ac_position + 1 <= question[1]:
            ac_count += 1

    print(ac_count)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
for i in range(q):
    tmp = s
    list_q = list(map(int, input().split()))
    list_q[0] = list_q[0] - 1
    list_q[1] = n - list_q[1]
    min_num = min(list_q)
    for j in range(min_num):
        tmp = tmp[1:]
        tmp = tmp[:-1]
    for k in range(list_q[0] - min_num):
        tmp = tmp[1:]
    for k in range(list_q[1] - min_num):
        tmp = tmp[:-1]
    tmp = tmp.split("AC")
    print(len(tmp) - 1)

Submission status: Time Limit Exceeded

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

input_list = []
for _ in range(Q):
    input_list.append(list(map(int, input().split())))

for i in range(Q):
    l, r = input_list[i][0], input_list[i][1]
    sub_str = S[l - 1 : r]
    print(sub_str.count(target))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input().strip())
arr=[]
for i in range(len(S)-1):
    if S[i]=="A" and S[i+1]=="C":
        arr.append(1)
    else:
        arr.append(0)
arr.append(0)
num=[]
for i in range(Q):
    l,r=map(int,input().split())
    num.append(sum(arr[l-1:r-1]))

for i in num:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = (int(i) for i in input().split())  
s = input()
for i in range(q):
    li,ri = (int(x) for x in input().split())
    sliceS = s[li-1:ri]
    cnt = sliceS.count('AC')
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from re import sub

def func(start, end, word):
    result = 0
    this_word = word[start-1:end]
    #print()
    #print(this_word)
    this_word = sub('[^AC]', ' ', this_word)
    this_word = sub('AC', 'AC ', this_word).split(' ')
    #print(this_word)
    for i in this_word:
        if i == 'AC':
            result += 1
    return result

config = input().strip().split(' ')
word_length = int(config[0])
question_num = int(config[1])

word = input().strip()
result = []

for i in range(question_num):
    config = input().strip().split(' ')
    start_index = int(config[0])
    end_index = int(config[1])
    ans = func(start_index, end_index, word)
    result.append(ans)

for i in result:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def MKNUMBER(ALL,l,r):
    number = ALL[l-1:r]
    return(number)
  
def countAC(number):
    count = 0
    flg = 0
    for i in number:
        if i == 0:
            flg = 0
        if i == 1:
            flg = 1
        if i == 2:
            if flg == 1:
                count = count + 1
            flg = 0
    print(count) 
    
N,Q = input().split()
N = int(N)
Q = int(Q)
S = input()
A=list(S)
ALL = []
for i in A:
        if i == "A":
            ALL.append(1)
        elif i == "C":
            ALL.append(2)
        else:
            ALL.append(0)
###print(ALL)
for i in range(0,Q):
    l,r = input().split()
    l = int(l)
    r = int(r)
    number = MKNUMBER(ALL,l,r)
    countAC(number)

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(str(S[l-1:r].count('AC')))

Submission status: Time Limit Exceeded

Solution code:
import re

def main():
    N, Q = map(int, input().split())
    S = input()
    inlist = [map(int, input().split()) for i in range(Q)]
    # inlist = [line.split(' ') for line in open(0).read().split('\n')]
#     print(re.findall("AC", S))

    for start, stop in inlist:
        start = start-1
        s = S[start:stop]
        print(len(re.findall("AC", s)))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
l_li=[]
r_li=[]
for i in range(q):
    l,r=map(int,input().split())
    l_li.append(l)
    r_li.append(r)
    
dp =[[0 for i in range(n)] for j in range(n)]

for j in range(n):
    t=0
    if s[j]=="C" and j!=0 and s[j-1]=="A":
        dp[0][j]=dp[0][j-1]+1
    else:
        dp[0][j]=dp[0][j-1]

for i in range(1,n):
    t=0
    if s[i]=="C" and s[i-1]=="A":   
        dp[i][i:n]=list(map(lambda x: x-1,dp[i-1][i:n]))
    else:
        dp[i][i:n]=dp[i-1][i:n]       
        
        
for i in range(q):
    print(dp[l_li[i]-1][r_li[i]-1])

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().strip().split(' '))
S = input()
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().strip().split(' '))


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()

starts = [0 for k in range(q)]
ends = [0 for k in range(q)]
for i in range(q):
    starts[i], ends[i] = map(int, input().split())

target = 'AC'
index = -1
astrs = []
while True:
    index = s.find(target, index + 1)
    if index == -1:
        break
    else:
        astrs.append(index+1)

tmp = len(astrs)
for i in range(q):
    ans = [x for x in astrs if x not in range(starts[i], ends[i])]
    print(tmp-len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
ls=[];rs=[]
for i in range(Q):
    l,r=map(int,input().split())
    ls.append(l)
    rs.append(r)
for j in range(Q):
    n=0;a=False
    for k in S[(ls[j]-1):(rs[j])]:
        if k!="A" and a==False:
            pass
        elif k=="A":
            a=True
        elif a:
            if k=="C":
                n+=1
            else:
                a=False
    print(n)

Submission status: Time Limit Exceeded

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

for _ in range(Q):
    tmp = 0
    cnt = 0
    l, r = map(int,input().split())
    for i in list(S[l-1:r]):
        if 'A' == i:
            tmp = 1
        elif tmp == 1 and 'C' == i:
            cnt += 1
            tmp = 0
        else:
            tmp = 0

    print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = input().split()
    S = input()

    for i in range(int(Q)):
        a, b = (int(x) for x in input().split())
        sss = S[a - 1: b]
        sss = sss.replace("AC", "1")
        count = sss.count("1")
        print(count)

    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
slst=[]
cnt=[]
for i in range(n-1):
  slst.append(s[i:i+2])
for a,b in enumerate(slst):
  if b=='AC':
    cnt.append(a)
l=[]
for i in range(q):
  x,y=map(int,input().split())
  num=0
  for j in cnt:
    if x-1<=j<=y-2:
      num+=1
  print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
s = input()
l = [0] * a

for x in range(a - 1):
    if s[x:x+2] == "AC":
        l[x] = 1

for x in range(b):
    i, j = map(int, input().split())
    print(sum(l[i-1:j-1]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 20:45:14 2019

@author: screamLab
"""

n,m = input().split()
s = input()
ans = 0
for i in range(int(m)):
    a,b = input().split()
    a = int(a)
    b = int(b)
    t = s[a-1:b]
    t += 'R'
    for y in range(len(t)):
        if y == len(t):
            break
        if t[y]== 'A' and t[y+1] == 'C':
            ans += 1
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n,q = map(int,input().split())
  
s = list(input())
a = list()

last_s = 'l'

for j in s:
  if last_s == 'A' and j=='C':
    a.append(1)
  else:
    a.append(0)
  last_s = j
#print(a)

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

Submission status: Time Limit Exceeded

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

ans = []
for i in range(Q):
    R = S[l[i][0]-1 : l[i][1]]
    print(R.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(input())
a = [0]*n
l=1
while l<n:
    if s[l-1]=="A" and s[l]=="C":
        a[l-1]=1
        l+=2
    else:
        a[l-1]=0
        l+=1
for i in range(q):
    x,y=map(int,input().split())
    print(sum(a[x-1:y-1]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
 
S = input()
 
lr = []
 
for q in range(Q):
  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,Q = map(int, input().split())

S = str(input())
l = np.empty(Q)
r = np.empty(Q)
for i in range (Q):
    l[i],r[i] = map(int, input().split())
for i in range (Q):
    a = int(l[i]-1)
    b = int(r[i])
    s2 = S[a:b-1]
    s3 = S[a+1:b]
    #print(s2)
    #print(s3)
    S2 = list(s2.replace('A','1').replace('C','0').replace('G','0').replace('T','0'))
    nps2 =  np.array([int(j) for j in S2])

    S3 = list(s3.replace('A','0').replace('C','1').replace('G','0').replace('T','0'))
    nps3 =  np.array([int(j) for j in S3])


    SS = (nps2*nps3).sum()


    print(SS)

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())
    m=0
    for j in range(l-1,r-1):
            if s[j:j+2]=="AC":
                m+=1
    print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
si = S.replace("AC","11")
si = si.translate(str.maketrans({"T":"0","G":"0","A":"0","C":"0"}))
for q in range(Q):
  l, r = map(int, input().split())
  if l>=2 and S[l-2:l]=="AC" and S[r-1:r+1]=="AC":
    print(int((np.sum(list(map(int,list(si[l-1:r]))))-2)/2))
  elif l>=2 and S[l-2:l]=="AC":
    print(int((np.sum(list(map(int,list(si[l-1:r]))))-1)/2))
  elif S[r-1:r+1]=="AC":
    print(int((np.sum(list(map(int,list(si[l-1:r]))))-1)/2))
  else:
    print(int(np.sum(list(map(int,list(si[l-1:r]))))/2))

Submission status: Time Limit Exceeded

Solution code:
import re

N, S = map(int, input().split(' '))
pattern = "AC+"
T = input()
for _ in range(S):
    fir,fin = map(int, input().split(' '))
    T_ = T[fir-1:fin]
    result = re.findall(pattern, T_)
    print(len(result))

Submission status: Time Limit Exceeded

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

res = [s[int(ls[i][0]) - 1:int(ls[i][1])].count('AC') for i in range(q)]

for h in res:
  print(h)

Submission status: Time Limit Exceeded

Solution code:
import re

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

for i in range(q):
    print(s[l[i]-1:r[i]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
A, B = map(int, input().split())
C = input()
N =[list(map(int, input().split())) for _ in range(B)]
for i in N:
  slice = C[int(i[0])-1:int(i[1])]
  print(slice.count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ints = input().split()
inp = list(input())
a = []
co = 0
for i in range(int(ints[1])):
    a.append([int(e) for e in input().split()])
for d in a:
    s = inp[d[0]-1:d[1]]
    s.append('N')
    for g,x in enumerate(s):
      if x == 'A':
        if s[g+1] == 'C':
          co += 1
    print(co)
    co = 0

Submission status: Time Limit Exceeded

Solution code:
def have_AC(str):
    count=0
    for i in range(len(str)-1):
        if(str[i:i+2]=="AC"):
            count=count+1
    return count

n,q=input().split() #nは文字の長さ　qは質問数
s=input() #Sは文字列
n=int(n)
q=int(q)
num=[]

for i in range(q):
    a,b=input().split()
    a=int(a) -1
    b=int(b)
    num.append(have_AC(s[a:b]))

for j in range(len(num)):
    print(num[j])

Submission status: Time Limit Exceeded

Solution code:
N ,Q = map(int, input().split())
S = input()
    
def countAC(S, r, l):
    data = S[r-1:l]
    cnt = 0
    for i in range(len(data)-1):
        if data[i]=='A':
            if data[i+1] == 'C':
                cnt+=1
    return cnt
  
ret = []

for i in range(Q):
    r, l = map(int, input().split())
    cnt = countAC(S, r, l)
    ret.append(str(cnt))
print('\n'.join(ret))

Submission status: Time Limit Exceeded

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

N,Q = map(int,input().split())
S = input()
#index = [list(map(int,input().split())) for i in range(Q)]

lst = [0] * N

for i in range(1,N):
    if S[i] == "C" and S[i-1] == "A":
        lst[i] = 1

ans = 0
for i in range(Q):
    head,tail = map(int,input().split())
    ans = sum(lst[head-1:tail])
    if lst[head-1] == 1:
        ans -= 1
    print(ans)
    ans = 0

Submission status: Time Limit Exceeded

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

ACIndex = []
findFrom = 0
while(1) :
    i = S[findFrom:].find("AC")
    if i == -1 :
        break
    else :
        ACIndex.append(i+findFrom)
        findFrom = i+1+findFrom


for i in range(Q) :
    count = 0
    l, r = map(int, input().split(" "))
    for j in ACIndex :
        if j>=l-1 and j<r-1 :
            count+= 1
    
    print(count)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int, input().split())
s = input()
a = [0 for i in range(q)]
for k in range(q):
    i,j = map(int, input().split())
    a[k] = [i,j]
for nums in a:
    print(s[nums[0]-1:nums[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
l_r = []
for i in range(Q):
    l_r.append(list(map(int, input().split())))
demand_count = []
for i in range(len(l_r)):
    print(S[l_r[i][0]-1: l_r[i][1]].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)]
for q in range(Q):
    q_lis = S[lr[q][0] -1:lr[q][1]]
    print(q_lis.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())
  s = S[l-1:r]
  print(s.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
import re
num,que = map(int,input().split(" "))
word = input()

for i in range(que):
    s,e = map(int,input().split(" "))
    ex_word = word[s-1:e]
    if "AC" not in ex_word:
        print("0")
        continue
    answer = len(re.findall("AC",ex_word))
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import re
N, Q = map(int, input().split())
S = input()
lr = list()
for _ in range(Q):
    lr.append(tuple(map(int, input().split())))
    
for i in lr:
    print(len(re.findall("AC", S[i[0]-1:i[1]])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

index = []
result = re.finditer('AC', S)
r_list = [0] * len(S)
for r in result:
    r_list[r.start()] = 1

for i in range(Q):
    count = 0
    l, r = lr[i]
    count = sum(r_list[l-1:r-1])
    print(count)

Submission status: Time Limit Exceeded

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

for i in range(q):
    l, r=map(int, input().split())
    l_list.append(l)
    r_list.append(r)


for i in range(q):#10**5
    count=0
    target_s=s[l_list[i]-1:r_list[i]]
    print(target_s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
def solve(N, Q, S, L_R):
    answers = [0] * Q
    ac_index = list()
    for i in range(len(S) - 1):
        s = S[i:i + 2]
        if s == "AC":
            for j in range(len(L_R)):
                l, r = L_R[j]
                if l <= i + 1 < r:
                    answers[j] += 1
    return answers


N, Q = map(int, input().split())
S = input()
L_R = [tuple(map(int, input().split())) for _ in range(Q)]
for ans in solve(N, Q, S, L_R):
    print(ans)

Submission status: Time Limit Exceeded

Solution code:


tmp = input().split(" ")
n = tmp[0]
q = int(tmp[1])

s = input()

ac_indexes=[]
start=0
while True:
    ind = s.find("AC", start)
    if ind != -1:
        start=ind+2
        ac_indexes.append(ind)
    else:
        break

memo = {}

for i in range(q):

    if len(ac_indexes) == 0:
        print ("0")
        continue

    tmp = input().split(" ")
    a = int(tmp[0]) - 1
    b = int(tmp[1]) - 2

    memo_ = memo.get(str(a) + "," + str(b))
    if memo_ != None:
        print (str(memo))


    left = 0
    right = len(ac_indexes)-1
    left_kari=-1
    left_kakutei = -1
    while left <= right:
        center = (left+right)//2
        if ac_indexes[center] > a:
            right = center-1
            left_kari = center
        elif ac_indexes[center] < a:
            left = center+1
        else:
            left_kakutei = center
            break
    if left_kakutei == -1:
        left_kakutei = left_kari
    
    left = 0
    right = len(ac_indexes)-1
    right_kari = -1
    right_kakutei = -1
    while left <= right:
        center = (left+right)//2
        #print (left, center, right)
        if ac_indexes[center] > b:
            right = center-1
        elif ac_indexes[center] < b:
            left = center+1
            right_kari = center
        else:
            right_kakutei = center
            break
    if (right_kakutei == -1):
        right_kakutei = right_kari

    if (left_kakutei > right_kakutei or left_kakutei==-1 or right_kakutei==-1):
        print ("0")
        continue

    print(str(right_kakutei - left_kakutei + 1))
    memo.update({str(a) + "," + str(b): (right_kakutei - left_kakutei + 1)})

Submission status: Time Limit Exceeded

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

def main():
    for i in range(Q):
        word_s = l[i][0] - 1
        word_e = l[i][1]
        print(S[word_s:word_e].count('AC'))

main()

Submission status: Time Limit Exceeded

Solution code:
import re

N, S = map(int, input().split(' '))
pattern = "AC+"
T = input()
for _ in range(S):
    fir,fin = map(int, input().split(' '))
    result = re.findall(pattern, T[fir -1:fin])
    print(len(result))

Submission status: Time Limit Exceeded

Solution code:
import sys

hajime = input().split(" ")
num = int(hajime[1])
word = input()

syori = [i for i in sys.stdin]

for i in syori:
  wakeru = i.split(" ")
  a = int(wakeru[0])
  b = int(wakeru[1])
  tmp = word[a-1:b]
  tmp_split = tmp.split("AC")
  hikaku = ("").join(tmp_split)
  print(int((len(tmp)-len(hikaku))/2))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
z = []
for j in range(N-1):
  if S[j]=='A' and S[j+1]=='C':
    z.append(j+1)
for i in range(Q):
  l,r = map(int,input().split())
  ans = [x for x in z if x >= l and x<= r-1]
  print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
s = input()
sMap = []
tmp = 0
count = []
L = []
R = []
for i in range(Q):
    a = list(map(int, input().split()))
    L.append(a[0])
    R.append(a[1])
    count.append(0)
for k in range(N-1):
    if s[k] == 'A' and s[k + 1] == 'C':
        for j in range(Q):
            if L[j]-1 <= k < R[j]-1:
                count[j] += 1
#         sMap.append(1)
#     else:
#         sMap.append(0)
# sMap.append(0)

for r in range(Q):
    # tmp = 0
    # for b in range(L[r]-1, R[r]-1):
    #     if sMap[b] == 1:
    #         tmp += 1
    # print(tmp)
    print(count[r])

Submission status: Time Limit Exceeded

Solution code:
#length => N, number => Q
counter = 0
N_Q = list(map(int, input().split(' ')))

S = input()
for _ in range(N_Q[1]):
  s_e = list(map(int, input().split(' ')))
  print(S[s_e[0]-1:s_e[1]].count('AC'))