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()
for i in range(q):
    l, r = map(int, input().split())
    S = s[l-1:r]
    ans = S.count('AC')
    print(ans)

Submission status: Time Limit Exceeded

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

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)]
for h,j in lr:
    print(s[h-1: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 _ in range(Q)]
#l = [lr[i][0] for i in range(Q)]
#r = [lr[i][1] for i in range(Q)]
#print(lr)
#print(l)
#print(r)

c = [0] * (N+2)
cnt = 0

for i in range(1,N+1):
    #if S[i]+S[i+1]=='AC':
        #c[i+1]+=1
    c[i] = S[:i].count('AC')

#print(c)

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

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)]
l = [lr[i][0] for i in range(Q)]
r = [lr[i][1] for i in range(Q)]
#print(lr)
#print(l)
#print(r)

c = [0] * (N+2)
cnt = 0

for i in range(1,N+1):
    #if S[i]+S[i+1]=='AC':
        #c[i+1]+=1
    c[i] = S[:i].count('AC')

#print(c)

for i,j in zip(l,r):
    #print(sum(c[:j])-sum(c[:i]))
    print(c[j]-c[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)]
l = [lr[i][0] for i in range(Q)]
r = [lr[i][1] for i in range(Q)]
#print(lr)
#print(l)
#print(r)

c = [0] * (N+2)
cnt = 0

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

#print(c)

for i,j in zip(l,r):
    print(sum(c[:j])-sum(c[:i]))

Submission status: Time Limit Exceeded

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,q = LI()
    s = "$" + S()

    for _ in range(q):
        l,r = LI()
        ans = s[l:r+1].count("AC")
        print(ans)
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())
  ans = 0
  for i in range(l-1, r-1):
    if s[i]=='A' and s[i+1]=='C':
      ans += 1
  
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = list(map(int, input().split(' ')))
x = input()+'l'
c = 0
for i in range(n[1]):
    y  = list(map(int, input().split(' ')))
    for j in range(y[0], y[1]):
        #print(x[j-1], x[j])
        if x[j-1] + x[j] == 'AC':
            c += 1
    print(c)
    c = 0

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().rstrip().split())
S = input().rstrip()
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    ans = 0
    for i in range(l-1,r-1):
        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().rstrip().split())
S = input().rstrip()
ans = 0
for _ in range(Q):
    l, r = map(int,input().rstrip().split())
    print(S[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(input())
lr = [list(map(int, input().split())) for _ in range(q)]
for i in range(n-1):
    if s[i] == "A" and s[i + 1] == "C":
        s[i] = "a"
for i in range(q):   
    l = s[lr[i][0] - 1 : lr[i][1]:]
    if l[-1] != "a":
        print(l.count("a"))
    else:
        print(l.count("a") - 1)

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = list(input())
lr = [list(map(int, input().split())) for _ in range(q)]
for i in range(q):
    l = s[lr[i][0] - 1 : lr[i][1]:]
    # print(l)
    count = 0
    while "A" in l:
        a_index = l.index("A")
        if a_index + 1 < len(l):
            if l[a_index + 1] == "C":
                count += 1
        # l.pop(a_index + 1)
        l.pop(a_index)
    print(count)

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 = list(map(int, input().split()))
s = input()
for _ in range(q):
    r,l=list(map(int, input().split()))
    print(s[r-1:l].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int, input().split()))
s = input()
s_ps=[]
for i in range(n-1):
    if s[i:i+2]=='AC':
        s_ps.append(i)

for _ in range(q):
    l,r=list(map(int, input().split()))
    count =0
    for i in s_ps:
        if l-1<=i and i < r-1:
            count +=1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
R=[]
for i in range(Q):
    A=list(map(int,input().split()))
    L.append(A[0])
    R.append(A[1])
def X(l,r):
    c=0
    T=S[l-1:r]
    for i in range(r-l):
        if T[i]=="A" and T[i+1]=="C":
            c+=1
    print(c)
for k in range(Q):
    X(L[k],R[k])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':

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

	#累積和を作成
	S = [0]
	tmp = ""
	for i in s:
		tmp = tmp + i
		S.append(tmp.count("AC"))

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

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
	n,q = map(int,input().split())
	s = input()

	#累積文字列を作成
	S = [""]
	tmp = ""
	for i in s:
		tmp = tmp + i
		S.append(tmp)

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

Submission status: Time Limit Exceeded

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

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.append(S[l-1: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 = input()
ans=[]

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

for i in range(len(ans)):
    print(ans[i].count('AC'))

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())
  for i in range(l,r):
    if s[i-1] == "A" and s[i] == "C": ans += 1
  print(ans)

Submission status: Time Limit Exceeded

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

ans = []
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    ans.append(i)

    
for s in range(Q):
  count = 0
  for i in ans:
    if a[s][0]-1<=i and a[s][1]-2>=i:
      count+=1
  print(count)

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[a-1:b].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:
n,q=map(int,input().split())
s=input()
c=[]
for i in range(n-1):
  if s[i:i+2]=="AC":
    c.append(i)
for i in range(q):
  a,b=map(int,input().split())
  print(len([_ for _ in c if (_>=a-1) and (_<b-1)]))

Submission status: Time Limit Exceeded

Solution code:
n,q=map(int,input().split())
s=input()
c=[]
for i in range(n-1):
  if s[i:i+2]=="AC":
    c.append(1)
  else:
    c.append(0)
for i in range(q):
  a,b=map(int,input().split())
  print(sum(c[a-1:b-1]))

Submission status: Time Limit Exceeded

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

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

for i in range(Q):
    count = 0 
    index = [i for i, x in enumerate(S[l[i] - 1: r[i]]) if x == "A"]
    for j in index:
        if S[i + 1] == "C":
            count += 1
    print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
acgt = ['A', 'T', 'G', 'C']
ac = 'AC'
L = []
R = []

n, q = map(int, input().strip().split())
word = input()

for _ in range(q):
    tmp_l, tmp_r = map(int, input().strip().split())
    L.append(tmp_l)
    R.append(tmp_r)

for i in range(q):
    res = 0
    for j in range(L[i] - 1, R[i]-1):
        if word[j] == 'A' and word[j + 1] == 'C':
            res += 1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, q = rm()
s = rr()
cnt_li = [s[:i].count('AC') for i in range(1, n+1)]
for _ in range(q):
    l, r = rm()
    print(cnt_li[r-1] - cnt_li[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())
    s = S[l-1:r]
    count = 0
    for j in range(r-l):
        if(s[j:j+2] == 'AC'):
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=str(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()
lr = [list(map(int, input().split())) for i in range(q)]
l = []
for i in range(n):
    if i < n-1:
        if s[i] == "A" and s[i+1] == "C":
            l.append("a")
        else:
            l.append(s[i])
    else:
        l.append(s[i])
ans = 0
for i in range(q):
    print(l[lr[i][0]-1:lr[i][1]-1].count("a"))

Submission status: Time Limit Exceeded

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, q = nm()
    S = input()
    ans = []
    for i in range(q):
        l, r = nm()
        ans += [S[l - 1:r].count('AC')]
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

idx = []
# n
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        idx.append(i)

for l, r in lrL:
    cnt = 0
    for x in idx:
        if x > r - 2:
            break
        if l - 1 <= x <= r - 2:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

idx = []
for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        idx.append(i)

for l, r in lrL:
    print(len(list(filter(lambda x: l - 1 <= x <= r - 2, idx))))

Submission status: Time Limit Exceeded

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

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

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())
    s = S.count("AC", l-1, r)
    ans.append(s)
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())
  
  string=s[l-1:r]
  print(string.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import collections
N,Q = map(int,input().split())
T = input()
S = T.replace("AC","WW")

for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    num = collections.Counter(S[l:r+1])["W"]//2
    if T[l] == "C" and T[r] == "A":
        num -= 1
    print(num)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc122/tasks/abc122_c
N,Q= map(int,input().split())
moji = str(input())
a_list = [i for i, x in enumerate(moji) if x == 'A']
Current_List =[]
for i in a_list:
    if i == N - 1:
        break
    elif moji[i+1] == "C":
        Current_List.append(i)

for i in range(Q):
    start,stop = map(int,input().split())
    print(len([j for j in Current_List if (j >=start-1) and (j < stop-1)]))

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc122/tasks/abc122_c
N,Q= map(int,input().split())
moji = str(input())
for i in range(Q):
    start,stop = map(int,input().split())
    print(moji[start-1:stop].count("AC"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#! python3
#  solve_122C.py

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

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

Submission status: Time Limit Exceeded

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

L = [0]*len(s)
for i in range(1,len(s)):
    if s[i-1] == "A" and s[i] == "C":
        L[i] = 1
   
for _ 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()
LR = [list(map(int, input().split())) for _ in range(q)]

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

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int, input().split())) 
s = input()
for _ in range(q):
    ql = list(map(int, input().split())) 
    ext_s = s[ql[0]-1:ql[1]]
    cnt = 0
    while 'AC' in ext_s:
        #print(ext_s)
        cnt += 1
        idx = ext_s.find('AC')
        ext_s = ext_s[:idx] + ext_s[idx+2:]
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int, input().split())) 
s = input()
for _ in range(q):
    ql = list(map(int, input().split())) 
    ext_s = s[ql[0]-1:ql[1]]
    blist = [ ext_s[i:i+2] for i in range(len(ext_s)-1)]
    print( blist.count('AC'))

Submission status: Time Limit Exceeded

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

for ql in qlist:
    ext_s = s[ql[0]-1:ql[1]]
    blist = [ ext_s[i:i+2] for i in range(len(ext_s)-1)]
    print( blist.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n,q = list(map(int, input().split())) 
s = input()
qlist = [list(map(int, input().split())) for _ in range(q)]
def check_ac(arg_s):
    cnt = 0
    for i in range(len(arg_s)):
        #print(arg_s[i:i+2])
        if arg_s[i:i+2] == 'AC':

            cnt += 1
    return cnt

for ql in qlist:
    #print(s[ql[0]-1:ql[1]] )
    print( check_ac( s[ql[0]-1:ql[1]] ))

Submission status: Time Limit Exceeded

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

for l,r in l_r:
    sub_s = s[l-1:r]
    print(len(sub_s.split('AC'))-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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


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

for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

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


for _ in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for idx in ac_idx:
        if idx >= l-1 and idx+1 <= r-1:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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

# In[8]:


N,Q = map(int, input().split())
S = input()
mylist = []
for i in range(len(S)-1):
    if S[i] == "A" and S[i+1] == "C":
        mylist.append(i)
for _ in range(Q):
    l,r = map(int, input().split())
    ans = [1 for x in mylist if l-1<= x and x+1<=r-1]
    print(sum(ans))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
z = [list(map(int,input().split())) for i in range(q)]
l,r = [list(i) for i in zip(*z)]
p = 0
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()

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

for l, r in lr:
    count = 0
    for i in range(l-1, r-1):
        if s[i:i+2]=='AC':
            i = i+1
            count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=list(input())
L=list()
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    S[i]="a"
t=[0]*(N+2)
for i in range(N):
  t[i+2]=S[:i+1].count("a")
for i in range(Q):
  n,m=map(int,input().split())
  print(t[m]-t[n])

Submission status: Time Limit Exceeded

Solution code:
N,Q=map(int,input().split())
S=input()
L=list()
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    L.append(i)
for i in range(Q):
  n,m=map(int,input().split())
  k= sum(1 for x in L if n-1<=x<m-1)
  print(k)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# abc122_c.py
# https://atcoder.jp/contests/abc122/tasks/abc122_c

# C - GeT AC /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# A, C, G, T からなる長さ Nの文字列 S が与えられます。以下の Q個の問いに答えてください。

#     問 i(1≤i≤Q): 整数 li,ri (1≤li<ri≤N) が与えられる。
#     S の先頭から li 文字目から ri文字目までの (両端含む) 部分文字列を考える。
#     この文字列に AC は部分文字列として何回現れるか。

# 注記
# 文字列 Tの部分文字列とは、T の先頭と末尾から 0文字以上を取り去って得られる文字列です。

# 例えば、ATCODER の部分文字列には TCO, AT, CODER, ATCODER, (空文字列) が含まれ、AC は含まれません。

# 制約
#     2≤N≤10^5
#     1≤Q≤10^5
#     Sは長さ N
#     の文字列である。
#     Sの各文字は A, C, G, T のいずれかである。
#     1≤li<ri≤N

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N Q
# S
# l1 r1
# :
# lQ rQ

# 出力
# Q行出力せよ。i 行目に問 iへの答えを出力すること。

# 入力例 1
# 8 3
# ACACTACG
# 3 7
# 2 3
# 1 8

# 出力例 1
# 2
# 0
# 3

#     問 1: S の先頭から 3 文字目から 7 文字目までの部分文字列は ACTAC です。この文字列に AC は部分文字列として 2回現れます。
#     問 2: S の先頭から 2 文字目から 3 文字目までの部分文字列は CA です。この文字列に AC は部分文字列として 0回現れます。
#     問 3: S の先頭から 1 文字目から 8 文字目までの部分文字列は ACACTACG です。この文字列に AC は部分文字列として 3 回現れます。


def calculation(lines):
    line = lines[1]
    # N = int(lines[0])
    N, Q = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))
    valueses = list()
    for i in range(Q):
        valueses.append(list(map(int, lines[i+2].split())))

    result = list()

    for values in valueses:
        # print('=====')
        l, r = values
        # l文字目～r文字目
        tmp = line[l-1:r]
        cnt = 0
        for i in range(len(tmp)-1):
            # print(tmp[i:i+2])
            if tmp[i:i+2] == 'AC':
                cnt += 1
        result.append(cnt)

    return result


# 引数を取得
def get_input_lines():
    line = input()
    N, Q = list(map(int, line.split()))
    lines = list()
    lines.append(line)
    for _ in range(Q+1):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['8 3', 'ACACTACG', '3 7', '2 3', '1 8']
        lines_export = [2, 0, 3]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    ans=0
    str=s[l[i]-1:r[i]]
    for j in range(len(str)-1):
        if (str[j]=="A")&(str[j+1]=="C"):
            ans+=1
        elif (str[j]=="A")&(str[j+1]!="A"):
            j+=2
        elif (str[j]!="A")&(str[j+1]!="A"):
            j+=2
    print(ans)

Submission status: Time Limit Exceeded

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

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

for i in range(q):
    ans=0
    str=s[l[i]-1:r[i]]
    for j in range(len(str)-1):
        if (str[j]=="A")&(str[j+1]=="C"):
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,q=I()
s = v()
a = []
for i in range(q):
    r = l()
    a.append(r)
for i in a:
    b = s[i[0]-1:i[1]]
    print(b.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
n, q = map(int, input().split())
S = input()
for _ in range(q):
    l, r = map(int, input().split())
    SS = S[l-1:r]
    rl = re.findall(r'AC', SS)
    print(len(rl))

Submission status: Time Limit Exceeded

Solution code:
import bisect
n,q=map(int,input().split())
s = input()
a=[]
for i in range(n-1):
  if s[i:i+2]=='AC':
    a.append(i)
for _ in range(q):
  b=list(a)
  l,r=map(int,input().split())
  l-=1.5
  r-=1.5
  bisect.insort(b,l)
  bisect.insort(b,r)
  print(b.index(r)-b.index(l)-1)

Submission status: Time Limit Exceeded

Solution code:
#<122>
N, Q = map(int,input().split())
S = input()
for q in range(Q):
    get_ac = ""
    l, r = map(int,input().split())
    get_ac = S[l-1:r]
    print(get_ac.count("AC"))

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())
  t=s[a-1:b]
  print(t.count('AC'))

Submission status: Time Limit Exceeded

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

i = 0
while i < N-1:
  if S[i] == 'A':
    if S[i+1] == 'C':
      S_ans[i] = 1
      i += 2
    elif S[i+1] == 'A':
      i += 1
    else:
      i += 2
  else:
    i += 1

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

Submission status: Time Limit Exceeded

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

i = 0
while i < N-1:
  if S[i] == 'A' and S[i+1] == 'C':
    S_ans[i] = 1
  i += 1

for i in range(Q):
  l, r = map(int, input().split())
  print(int(sum(S_ans[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:
n,q=map(int,input().split())
s=input()
l,r=[],[]
c=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)
for i in range(n-1):
    if  s[i]=="A" and s[i+1]=="C":
        c[i]=1
for i in range(q):
    print(sum(c[(l[i]-1):(r[i]-1)]))

Submission status: Time Limit Exceeded

Solution code:
import re
import numpy as np
n, q=map(int, input().split())
s=str(input())
l = []
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    l.append(i)
l=np.array(l)
for _ in range(q):
  a, b=map(int, input().split())
  print(np.count_nonzero((a-1 <= l) & (l < b-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 range(Q):
    w = S[lr[i][0]-1:lr[i][1]]
    print(w.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
import re
n, q=map(int, input().split())
s=str(input())
#for ra
l = [0 for _ in range(n)]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    l[i]=1
for _ in range(q):
  a, b=map(int, input().split())
  print(sum(l[a-1:b-1]))

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
n,q=map(int,input().split())
s=input()
a=[]
for x in range(n-1):
  if s[x]=='A' and s[x+1]=='C':
    a.append(x)
    
for y in range(q):
  ans=0
  l,r=map(int,input().split())
  ans+=sum(1 for i in a if i>=l-1 and i<=r-2)
  print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for q in quiz:
  l = q[0]
  r = q[1]
  print(S[l-1:r].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
lr = [map(int,input().split()) for a in range(q)]
l,r = [list(b) for b in zip(*lr)]

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

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)]
for l in L:
  print(S[l[0]-1:l[1]].count("AC"))

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
z = [list(map(int,input().split())) for i in range(q)]
l,r = [list(i) for i in zip(*z)]

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