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() 
data = [ tuple(map(int, input().split())) for _ in range(Q) ] 

indexList = [0 for _ in range(N)]
index = -1
while True:
	index = S.find("AC", index+1)

	if index == -1:
		break
	
	indexList[index] = 1

# print(indexList)

for (l, r) in data:
	# print(indexList[l-1: r-1])
	print(sum(indexList[l-1: r-1]))

Submission status: Time Limit Exceeded

Solution code:
A = "AC"
N, Q = map(int, input().split())
S = list(input())
ans = [0] * (N - 1)
ind = 0
for i in range(N):
    try:
        ind = S.index('A', ind)
        if S[ind + 1] == 'C':
            ans[ind] = 1
        ind = ind + 1
    except:
        break


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

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int,input().split())
S = str(input())
S_list = []
for i in range(0,N,1):
    S_list.append(S[i:i+2])
del S_list[-1]
for j in range(Q):
    tmp = []
    l, r = map(int,input().split())
    for k in range(l,r,1):
        tmp.append(S_list[k-1])
    print(tmp.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, Q = map(int, input().split())
S = input()
ls, rs = [], []
for _ in range(Q):
    l, r = map(int, input().split())
    ls.append(l-1)
    rs.append(r-1)

arr = np.zeros(N, np.int)
flag = False
for i in range(len(S)):
    if S[i] == 'A':
        flag = True
    elif S[i] == 'C' and flag:
        arr[i - 1] = 1
    else:
        flag = False

for l, r in zip(ls, rs):
    print(np.sum(arr[l:r]))

Submission status: Time Limit Exceeded

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

for test in range(q):
	l, r = map(int, input().split())

	count = 0
	for i in range(l-1, r-1):
		current = s[i] + s[i+1]
		if current == "AC":
			count += 1

	print(count)

Submission status: Time Limit Exceeded

Solution code:
# C
import numpy as np
n, q = map(int, input().split())
s = str(input())
s_flag = [0] * n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        s_flag[i] = 1
s_flag = np.array(s_flag)
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = np.sum(s_flag[l:r+1])
    if s_flag[r:r+1] == 1:
        ans -=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S=input()
l=list()
r=list()
for i in range(Q):
  LandR=list(map(int,input().split()))
  l.append(LandR[0])
  r.append(LandR[1])
  S2=S[l[i]-1:r[i]].split("AC")
  print(len(S2)-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:
a, b = map(int, input().split())

A = input()
B = []
for i in range(a-1):
    if(A[i] == 'A' and A[i+1] == 'C'):
        B.append(i)

for j in range(b):
    x, y = map(int ,input().split())
    ans= 0
    for k in B:
        if(k>=x-1):
            if(k<=y-2):
                ans+=1
            else:
                break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, Q = [int(i) for i in input().split()]
S = input()
L = []
for j in range(Q):
    L.append([int(i) for i in input().split()])
for i in L:
    tar = S[i[0]-1:i[1]]
    if "A" not in tar or "C" not in tar or "AC" not in tar:
        print(0)
        continue
    else :
        print(tar.count("AC"))

Submission status: Time Limit Exceeded

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

li = []
for i in range(Q):
    s = lr[i][0] - 1
    l = lr[i][1]
    tempS = S[s:l]
    li.append(tempS)

for j in range(Q):
    result = re.findall(r'AC', li[j])
    print(len(result))

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(input())
sum=0
for i in range(Q):
    l,r=map(int,input().split())
    num=S.count('AC',l-1,r)
    print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    SL = [0 for _ in range(len(S) + 1)]
    for i in range(1, len(S)):
        if S[i - 1:i + 1] == 'AC':
            SL[i] = 1
    ans = []
    for _ in range(Q):
        l, r = map(int, input().split())
        s = sum(SL[l:r])
        ans.append(s)
    for a in ans:
        print(a)


main()

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

Submission status: Time Limit Exceeded

Solution code:
import sys

N, Q = map(int, sys.stdin.readline().split())
S = input()
s = [0] * Q
ans = 0

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

for j in range(Q):
    print(s[j])

Submission status: Time Limit Exceeded

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

def AC_counter(l, r):
    tmp = S[l-1:r]
    print(tmp.count('AC'))

for _ in range(Q):
    l, r = map(int, input().split())
    AC_counter(l, r)

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 lr:
    q_lis = S[q[0]-1:q[1]:]
    print(q_lis.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=str(input())
lr=[list(map(int,input().split())) for i in range(q)]
#na=list(map(lambda x:s[x[0]-1:x[1]].count("AC"),lr))
for i in list(map(lambda x:s[x[0]-1:x[1]].count("AC"),lr)):
    print(i)

Submission status: Time Limit Exceeded

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

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

for now in lr:
    l, r = now[0]-1, now[1]
    tmp = s[l:r]
    print(tmp.count('AC'))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

ans = []
for li in l:
    ps = S[li[0]-1:li[1]]
    num = 0
    for e1, e2 in zip(ps, ps[1:]):
        if e1 == 'A' and e2 == 'C': 
            num += 1
    print(num)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ac_list = [0]*len(s)
i = 0
'''while True:
    ac_index = s[i:].find("AC")
    if ac_index == -1:
        break
    else:
        ac_list[ac_index+i] = 1
        i = ac_index + i + 2'''

for i in range(len(s)-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list[i] = 1

for _ in range(q):
    lr = tuple(map(int, input().split()))
    print(sum(ac_list[lr[0]-1:lr[1]-1]))

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())
    ans += str(s[l-1:r].count('AC')) + '\n' if i != (q-1) else str(s[l-1:r].count('AC'))
print(ans)

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())
answer=[0]*Q
for j in range(Q):
  counter=[0]*(r[j]-l[j]+1)
  for i in range(len(counter)):
    if i==len(counter)-1:
      answer[j]=sum(counter)
      break
    if S[l[j]-1+i]=="A":
      if S[l[j]+i]=="C":
        counter[i]=1
      else:
        counter[i]=0
    else:
      counter[i]=0
for i in range(len(answer)):
  print(answer[i])

Submission status: Time Limit Exceeded

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

l_list = []
r_list = []

for x in range(Q):
    l, r = map(int, input().split())
    sub_str = S[l-1:r]
    ac_count = 0
    
    for i in range(len(sub_str) - 1):
        if sub_str[i:i+2] == 'AC':
            ac_count += 1
    
    print(ac_count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, Q = map(int, input().split())
    S = input()
    s_list = [str(c) for c in S]
    q_list = [list(map(int, input().split())) for i in range(Q)]

    ac_list = list()
    # get AC start point
    for i, n in enumerate(s_list):
        if n == "A" and i != (len(s_list) - 1):
            if s_list[i + 1] == "C":
                ac_list.append(i + 1)

    # answer Q
    for qs in q_list:
        counter = 0
        for start in ac_list:
            if qs[0] <= start and start < qs[1]:
                counter += 1
            if start >= qs[1]:
                break
        print(counter)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(q):
    cnt = 0
    start = int(lr[i][0])-1
    end = int(lr[i][1])-1

    cnt = s[start:(end+1)].count('AC')

    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())
c = input()
li = []

for i in range(b):
    d,e = map(int,input().split())
    c_ = c[d-1:e]
    li.append(c_.count("AC"))
for i in li:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = str(input())
def f():
  l, r = map(int, input().split())
  count = 0
  a = False
  for s in S[l-1:r]:
    if s == 'A':
      a = True
    elif s == 'C' and a == True:
      count += 1
  print(count)
for i in range(Q):
  f()

Submission status: Time Limit Exceeded

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

for i in range(q):
  a,b=list(map(int, input().split()))
  s = S[a-1:b]
  counter=0
 
  for j in range(len(s)-1):
    if s[j] == "A":
      if s[j+1] == "C":
        counter +=1

  print(counter)

Submission status: Time Limit Exceeded

Solution code:
n,q= map(int,input().split())
S = input()
s = 0
for i in range(q):
  s = S
  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 = input()
for x in range(Q):
    a, b = map(int, input().split())
    s1 = S[a-1:b]
    s2 = s1.replace('AC', '')
    print(int((len(s1) - len(s2)) / 2))

Submission status: Time Limit Exceeded

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

for i in range(Q):
        cnt = 0
        l,r = lr[i][0],lr[i][1]
        x = S[l-1:r]
        for k in range(len(x)):
                if k - 1 >= 0:
                    if x[(k - 1):(k + 1)] == 'AC':
                            cnt += 1
        print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import re

def solv(s, l, r):
    s = s[l-1:r]
    return s.count('AC')


if __name__ == '__main__':

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

    for _ in range(q):
        l, r = map(int, input().split())
        ans = solv(s, l, r)
        print(ans)

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 lr_ in lr:
    l, r = lr_[0], lr_[1]
    cnt = 0
    
    for i in range(len(S[l - 1: r])):
        
        if(S[l - 1: r][i: i + 2] == '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(N):
    ans.append(S[:i+1].count('AC'))

for _ in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(ans[r-1])
    else:
        b = ans[r-1]-ans[l-2]
        if S[l-1] != 'C' and S[r-1] != 'A':
            print(b)
        elif S[l-1] == 'C' and S[l-2] == 'A':
            print(b-1)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int, input().split())
S = list(input())
lr = [list(map(int,input().split())) for i in range(Q)]
bef = ''
pos = []
for idx,val in enumerate(S):
    if val == 'C' and bef == 'A':
        pos.append((idx -1) * 10 + idx)
    bef = val

cnt = 0
for i in range(Q):
    min_v = (lr[i][0] - 1) * 10 + lr[i][0]
    max_v = (lr[i][1] - 2) * 10 + (lr[i][1] - 1)
    for p in pos:
        if p >= min_v and p <= max_v:
            cnt += 1
    print(cnt)
    cnt = 0

Submission status: Time Limit Exceeded

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

for _ in range(q):
  cnt = 0
  a, b = map(int, input().split())
  sub = s[a-1:b]
  for i in range(len(sub)-1):
    if sub[i:i+2] == "AC":
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

# In[35]:


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

lr=[list(map(int,input().split())) for l in range(Q)]

for i in range(Q):
    t=S[lr[i][0]-1:lr[i][1]]
   # t=[S for j in range(lr[i][0],lr[i][1])]
    #print(t)
    print(t.count('AC'))
    if i==Q:
        break


# In[ ]:

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for l, r in p:
    sub_str = S[l-1:r]
    print(sub_str.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/24
@author: shinjisu
"""


# ABC 122
# import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)
def getIntLines(n): return [int(input()) for i in range(n)]
def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N, Q = getIntList()
    d.dmp((N, Q), 'N, Q')
    S = input()
    d.dmp((S), 'S')
    for i in range(Q):
        L, R = getIntList()
        #d.dmp((L, R), 'L, R')
        j = L-1
        count = 0
        while j < R-1:
            #d.dmp(j,'j')
            #d.dmp(S[j:j+2],'S[j:j+2]')
            if S[j:j+2] == 'AC':
                count += 1
                j += 2
            else:
                j += 1
        print(count)
    return None

ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

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
ptn = re.compile(r"(A|C|T|G)*")

for l, r in LR:
  x = ptn.match(S[l-1:r])
  if(x.group(0)):
    xx = x.group(0)
    print(xx.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
N,Q = (int(i) for i in input().split())
S = input()
acl = []
flag = False
cnt = 0

for j in range(N):
    if S[j] == 'A':
      flag = True
    elif S[j] == 'C' and flag:
      acl.append(j-1)
      flag = False
    else:
      flag = False

for k in range(Q):
  x,y = (int(i)-1 for i in input().split())
  cnt = 0
  for m in acl:
    if m >= x and m < y:
      cnt += 1
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def f(S, l, r):
  sub = S[l-1:r]
  N = len(sub)
  count = 0
  for i in range(N-1): # 最後の文字がAでも意味ない
    if sub[i] == "A":
      if sub[i+1] == "C":
        count += 1
  return count

if __name__ == "__main__":
  N, Q = map(int, input().split())
  S = input()
  for _ in range(Q):
    l, r = map(int, input().split())
    print(f(S, l, r))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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

S = S.split('AC')
S = [len(s) + 2 * i for i, s in enumerate(S)][:-1]

A = np.array([[0 for r in range(N)] for l in range(N)])

for s in S:
    A[:s+1, s+1:] += 1

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

Submission status: Time Limit Exceeded

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

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

for q in range(Q):
  s_q = s[l_list[q]-1:r_list[q]]
  cnt = 0
  
  for i in range(len(s_q)-1):
    if s_q[i] == 'A' and s_q[i+1] == 'C':
      cnt += 1
  
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re

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

lr_list=[input() for i in range(q)]

for lr in lr_list:
    l,r = map(int, lr.split())
    print(len(re.findall('AC',s[l-1:r])))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
count_l=[]
for i in range(Q):
    a,b = map(int,input().split())
    flag=False
    counting=0
    if b==N:
        l=S[a-1:]
    else:
        l=S[a-1:b]
    #print(l)
    counting = l.count("AC")
    """for ii in l:
        #print(ii)
        if ii=="A":
            flag=True
        elif ii=="C" and flag==True:
            counting+=1
            flag=False"""
    count_l.append(counting)
for i in count_l:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(Q):
    s = S[l[i]-1:r[i]]
    state = 0
    ans = 0
    for j in s:
        if(state == 0):
            if(j == 'A'):
                state = 1
        elif(state == 1):
            if(j == 'C'):
                ans +=1
            state = 0
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(Q):
        cnt = 0
        l,r = lr[i][0],lr[i][1]
        x = S[l-1:r]
        x = x.replace('G','').replace('T','')
        for k in range(len(x)):
                if k - 1 >= 0:
                    if x[(k - 1):(k + 1)] == 'AC':
                            cnt += 1
        print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def count(S,l,r):
    s = S[l-1:r]
    ans=0
    for i in range(len(s)-1):
        if s[i]=='A' and s[i+1]=='C':
            ans+=1
            i+=1
    return ans
            
N,Q = map(int,input().split())
S=list(input())
li=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
    print(count(S, li[i][0], li[i][1]))

Submission status: Time Limit Exceeded

Solution code:
n, q = [int(i) for i in input().split() ]
s = input() #文字列
lr = list([])
for i in range(q):
    lr.append([int(i) for i in input().split() ])

ll = list([])
for i, c in enumerate(s):
    if((c == "A") and (i+1 <n) and (s[i+1] =="C")):
        ll.append(i+1)

for i in range(q):
    ans = 0
    for m in ll:
        if (m >= lr[i][0]) and (m+1 <=lr[i][1]):
            ans += 1
        elif m >= lr[i][1]:
            break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int, input().split())
S = input()
ac_index = np.zeros(len(S), dtype=np.int)
for i in range(len(S)-1):
    if(S[i]=='A' and S[i+1]=='C'):
        ac_index[i] = 1
    else:
        ac_index[i] = 0
        
for i in range(Q):
    l, r = map(int, input().split())
    print(sum(ac_index[l-1:r-1]))

Submission status: Time Limit Exceeded

Solution code:
N, Q = [int(x) for x in input().split()]
S = input()
for _ in range(Q):
	l, r = [int(x) for x in input().split()]
	S_dum = ''.join(S[l-1:r].split("AC"))
	print(int((len(S[l-1:r])-len(S_dum))/2))

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
lrs = []
for _ in range(Q):
	l,r = map(int,input().split())
	lrs.append([l,r])
	
for q in lrs:
	s = S[q[0]-1:q[1]]
	#print("s:",s,q[0]-1,q[1])
	print(s.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
nums = [list(map(int, input().split())) for i in range(q)]
for m in nums:
    s2 = s[m[0]-1:m[1]]
    s2 = s2.split("AC")
    print(len(s2)-1)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import deque

N, Q = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
lr_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(Q)]


for l, r in lr_list:
    stack = deque([])
    S2 = S[l-1:r]
    count = 0
    #print(S2)
    flg = False
    for s in S2:
        if s == "A":
            flg = True
        elif s == "C" and flg:
            count += 1
            flg = False
        else:
            flg = False
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
T = S.replace("AC", "@@")
for i in range(Q):
    l, r = map(int, input().split())
    num = list(T[l-1:r]).count("@") // 2
    if S[l-1] == 'C':
        num -= 1
    if S[r-1] == 'A':
        num -= 1
    print(max(num, 0))

Submission status: Time Limit Exceeded

Solution code:
import re

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

while k < i:
    ft, et = [int(n) for n in input().split()]
    result.append(len(re.findall("AC", s[ft - 1:et])))
    k += 1

for kekka in result:
    print(kekka)

Submission status: Time Limit Exceeded

Solution code:
#n=int(input())
#li=input().split()
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import math
#import numpy as np

lis=[]
#N Q
li=list(map(int,input().split()))
S=input()
for i in range(li[1]):
    #l_i r_i
    lr=list(map(int,input().split()))
    lis.append(lr)
for i in range(li[1]):
    ans=0
    for j in range(lis[i][1]-lis[i][0]):
        if S[lis[i][0]+j-1:lis[i][0]+j+1]=="AC":
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:


# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 03:17:55 2019

@author: rubug
"""

# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)

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

Submission status: Time Limit Exceeded

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

is_ac = [0] * n

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

for item in lr:
  ans = sum(is_ac[item[0]-1: item[1]])
  if s[item[1]-1] == "A" and item[1] != n:
    if s[item[1]] == "C":
      ans -= 1
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

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

for l, r in l_r:
    print(sum(isAC[l - 1:r - 1]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, Q = map(int,input().split())
S= input()
ac_pos_list = []
start = 0
ret = 0
while ret != -1:
    ret = S.find('AC',start)
    if ret != -1:
        ac_pos_list.append(ret)
        start = ret + 2        
ac_pos_list = np.array(ac_pos_list)

for i in range(Q):
    l,r = map(int,input().split())
    l = l-1
    r = r-1
    ans = np.sum((ac_pos_list>=l) & (ac_pos_list<=r-1))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
line = list(input())
AC_locate = []
count_s = []
for i in range(N-1):
    if line[i] == 'A' and line[i+1] == 'C':
        AC_locate.append(int(i))
for i in range(Q):
    l,r = map(int,input().split())
    count = 0
    for locate in AC_locate:
        if locate > r-2:
            break
        if locate >= l-1:
            count += 1
    # for i in range(l-1,r):
    #     if line[i] == 'A' and line[i+1] == 'C':
    #         count += 1
    count_s.append(count)
for c in count_s:
    print(c)

Submission status: Time Limit Exceeded

Solution code:



# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 03:17:55 2019

@author: rubug
"""

# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np

N,Q = map(int,input().split())
s = str(input())
S = []
for c in s:
    S.append(c)

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
s=list(input())
l=[]
def times(l,s):
    first=l[0]-1
    last=l[1]
    ss=[]
    count=0
    #5,4
    for i in range(first,last):
        ss.append(s[i])
    #print(ss)
    for i in range(len(ss)-1):
        if ss[i]=='A' and ss[i+1]=='C':
            count+=1
    return count

for i in range(Q):
    a=list(map(int,input().split()))
    l.append(a)
#print(l)

    
for c in l:
    ans=times(c,s)
    print(ans)

Submission status: Time Limit Exceeded

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

acgt = ['A', 'C', 'G', 'T']

for s in S_lr:
    count = 0
    A_flag = False
    for i, c in enumerate(s):
        if c == 'C' and i-1 > -1 and s[i-1] == 'A':
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
#C

N,Q =map(int,input().split())
S = input()
List=[[int(j) for j in input().split()] for i in range(1,Q+1)]
for i in range(Q):
    print(S[List[i][0]-1:List[i][1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re

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

while Q > 0:
    r, l = map(int, input().split())

    s = re.findall('AC', S[r-1:l])
    print(len(s))

    Q -= 1

Submission status: Time Limit Exceeded

Solution code:
n,q = [int(i) for i in input().split()]
s = input()

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

Submission status: Time Limit Exceeded

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

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

for _ in range(Q):
  l, r = map(int, input().split())
  i = l - 1
  cnt = 0
  while i < r - 1:
    if S[i] == "A" and S[i + 1] == "C":
      cnt += 1
      i += 2
    else:
      i += 1
  print(cnt)

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())
    a = s[l-1:r:]
    le = len(a)
    cnt = 0
    for j in range(le-1):
        if a[j:j+2:] == 'AC':
            cnt +=1
    print(cnt)

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())
    s1 = s[l-1:r].replace("AT", " ")
    s2 = s1.replace("AG", " ")
    s3 = s2.replace("TC", " ")
    s4 = s3.replace("TG", " ")
    print(s4.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
a, b = map(int, input().split())
c = [str(i) for i in input()]

d = [[int(i) for i in input().split()] for i in range(b)]

ans = 0
#print(d[1][0])

for i in range(b):
    for j in range(d[i][0]-1,d[i][1]-1):
        if c[j] == "A" and c[j+1] == "C":
            ans+=1
    print(ans)
    ans=0

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(str(input()))
s_1 = s[1:]
diff = []
for i in range(len(s)-1):
    if (s[i] == "A") & (s_1[i] == "C"):
        diff.append(1)
    else:
        diff.append(0)
for i in range(q):
    i = [int(i) for i in input().split()]
    ans = sum(diff[i[0]-1:i[1]-1])
    print(ans)