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: Wrong Answer

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

S_sub = S

S = S.replace("AC", "__")

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

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

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
S = input()
start = []
end = []
ans = []
for i in range(q):
    s,e = [int(i) for i in input().split()]
    count = 0
    for i in range(len(S[s:e])):
        if(S[i] == "A") and (S[i+1] == "C"):
            count+=1
    print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = [0]*N
tmp = 0
for i,c in enumerate(S):
    if tmp == 0 and c == "A":
        tmp =1
        cnt[i] = cnt[i-1]
    elif tmp == 1 and c == "C":
        tmp =0
        cnt[i] = cnt[i-1]+1
    else:
        cnt[i] = cnt[i-1]

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

Submission status: Wrong Answer

Solution code:
def get_ac(N: int, Q: int, S: str, queries: list)->list:
    before = ''
    cum = [0] * (N+1)
    for i, c in enumerate(S):
        cum[i+1] = cum[i]
        if before + c == 'AC':
            cum[i+1] += 1
        before = c

    print(cum)

    res = []
    for l, r in queries:
        res.append(cum[r] - cum[l])

    return res


if __name__ == "__main__":
    Q = 0
    N, Q = map(int, input().split())
    S = input()
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]
    ans = get_ac(N, Q, S, queries)
    
    for a in ans:
        print(a)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, Q = mi()
S = li()
Alist = []
for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        Alist.append(i)
AClist = [0]*N
for i in range(N - 1):
    if i in Alist:
        AClist[i + 1] = AClist[i] + 1
    else:
        AClist[i+1] = AClist[i]
AClist.insert(0, 0)
print(AClist)
for i in range(Q):
    l, r = mi()
    print(AClist[r] - AClist[l])

Submission status: Wrong Answer

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

flag = False
loc = [0 for i in range(n)]
tot  = 0

for i in range(n):
    if flag and s[i] == "C":
        tot += 1
        loc[i]=tot
        continue

    if s[i] == "A":
        flag = True
    else:
        flag = False
    loc[i] = tot

for qs in query:
    print(loc[qs[1]]-loc[qs[0]])

Submission status: Wrong Answer

Solution code:
N, Q = (int(i) for i in input().split())
S = input()

AC_list = [0] * N

for i in range(N-1):
    if(S[i+1]=="C"):
        if(S[i]=="A"):
            AC_list[i+1] = 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
S += 'J'
L = []
for i in range(Q):
  L.append(list(map(int,input().split())))
cnt = [0]*(N+1)
for i in range(N):
  if S[i] == 'A' and S[i+1] == 'C':
    cnt[i+1] = 1
for i in range(1,N+1):
  cnt[i] += cnt[i-1]
for j in range(Q):
  print(cnt[L[j][1]-1]-cnt[L[j][0]-1])
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
S=input()
query=[[int(i) for i in input().split()]for i in range(Q)]
L=[0]*(N+1)
t=0
for i in range(N):
    a=0
    if t==1 and S[i]=='C':
        a=1
        t=0
    elif S[i]=='A':
        t=1
    L[i+1]=L[i]+a
#print(L)
for a,b,in query:
    t=L[b]-L[a-1]
    #print(L[b],L[a-1],b,a)
    if a>=2 and S[a-1]=='C' and S[a-2]=='A':
        t-=1
    print(t)

Submission status: Wrong Answer

Solution code:
def main():
    N, Q = [int(q) for q in input().split()]
    S = input()
    lr = [
        [int(q) - 1 for q in input().split()]
        for _ in range(Q)
    ]

    ttt = [0]
    res = 0
    for i in range(1, len(S)):
        if S[i - 1] == "A" and S[i] == "C":
            res += 1
        ttt.append(res)
    print(ttt)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    b = S()
    b = b[0]
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    elif b == "G":
        print("C")
    return

#B
def B():
    s = S()
    agct = ["A", "G", "C", "T"]
    ans = 0
    for num, i in enumerate(s):
        ansb = 0
        if i in agct:
            ansb += 1
            for k in range(num+1, len(s)):
                if s[k] in agct:
                    ansb += 1
                else:
                    break
        ans = max(ans, ansb)
    print(ans)
    return

#C
def C():
    n, q = LI()
    s = S()
    ans = [0 for i in range(n)]
    ac = 0
    for num, ss in enumerate(s):
        if ac and ss == "A":
            ac = 1
            ans[num] = ans[num-1]
        elif not ac and ss == "C":
            ac = 0
            ans[num] += ans[num - 1] + 1
        else:
            ac = 0
            ans[num] = ans[num-1]
    for _ in range(q):
        l, r = LI_()
        print(ans[r]-ans[l])


    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
n, q = [int(i) for i in input().split()]
s = input()
l_list = []
r_list = []
for i in range(q):
    l, r = [int(i) for i in input().split()]
    l_list.append(l)
    r_list.append(r)

ac_map = [0 for i in range(n+1)]
for i in range(1, n+1):
    if s[i-1:i+1] == "AC":
        ac_map[i] = ac_map[i-1] +1
    else:
        ac_map[i] = ac_map[i-1]
print(ac_map)
for i in range(q):
    ans = ac_map[r_list[i]-1] - ac_map[l_list[i]-1]
    print(ans)

Submission status: Wrong Answer

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

ruiseki = [0]*(n+1)
for i in range(1,n+1):
  if s[i-1]+s[i] == "AC" :
    ruiseki[i] = ruiseki[i-1] + 1
  else:
    ruiseki[i] = ruiseki[i-1]
print(ruiseki)
for i in range(q):
  print(ruiseki[info[i][1]]-ruiseki[info[i][0]])

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    b = S()
    b = b[0]
    if b == "A":
        print("T")
    elif b == "T":
        print("A")
    elif b == "C":
        print("G")
    elif b == "G":
        print("C")
    return

#B
def B():
    s = S()
    agct = ["A", "G", "C", "T"]
    ans = 0
    for num, i in enumerate(s):
        ansb = 0
        if i in agct:
            ansb += 1
            for k in range(num+1, len(s)):
                if s[k] in agct:
                    ansb += 1
                else:
                    break
        ans = max(ans, ansb)
    print(ans)
    return

#C
def C():
    n, q = LI()
    s = S()
    ans = [0 for i in range(n)]
    ac = 0
    for num, ss in enumerate(s):
        if ac and ss == "A":
            ac = 1
        elif not ac and ss == "C":
            ac = 0
            ans[num] += ans[num - 1] + 1
        else:
            ac = 0
            ans[num] = ans[num-1]
    for _ in range(q):
        l, r = LI_()
        print(ans[r]-ans[l])


    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Wrong Answer

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

for q in range(Q):
    l, r= map(int,input().split())
    total = preC[r - 1]
    if l == 1:
        print(total)
    else:
        total -= preC[l - 2]
        if S[l] == 'A' and S[l - 1] == 'C':
            total -= 1
        print(total)

Submission status: Wrong Answer

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

from itertools import accumulate

prev = ""
acc = [0] * N
for i, s in enumerate(S):
    if "C" and prev == "A":
        acc[i] = 1
    prev = s
acc = list(accumulate(acc))
ans = []
for i in range(Q):
    l, r = items[i]

    ans.append(acc[r -1] - acc[l-1])
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
a = list(input())
ans = 0
count = 0
for i in a:
     if i in ['A','T','C','G']:
          count += 1
     else:
          ans = max(count,ans)
ans = max(count,ans)
print(ans)

Submission status: Wrong Answer

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

imos = [0 for i in range(N)]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        imos[i]=1
for i in range(N-1):
    imos[i+1]+=imos[i]
for l,r in lr:
    res = imos[r]
    if l>0:
        res-=imos[l-1]
    if S[r]=='A':
        res-=1
    print(res)

Submission status: Wrong Answer

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

for i in range(num):
  wakeru = input().split(" ")
  count = 0
  a = int(wakeru[0])
  b = int(wakeru[1])
  tmp = word[a:b]
  for j in range(len(tmp)-1):
    if tmp[j]=="A":
      if tmp[j+1]=="C":
        count+=1
  print(count)

Submission status: Wrong Answer

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

imos = [0 for i in range(N)]
for i in range(N-1):
    if S[i]=='A' and S[i+1]=='C':
        imos[i]=1
for i in range(N-1):
    imos[i+1]+=imos[i]
for l,r in lr:
    res = imos[r]-imos[l]
    if S[l]=='A':
        res+=1
    if S[r]=='A':
        res-=1
    print(res)

Submission status: Wrong Answer

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

cumsum = [0] * (N + 10)
for i in range(N - 1):
    cumsum[i] = cumsum[i - 1]
    if S[i:i + 2] == 'AC':
        cumsum[i] += 1

print(cumsum)
for l, r in LR:
    print(cumsum[r - 2] - cumsum[l - 2])

Submission status: Time Limit Exceeded

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

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

ac=[0]*n

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

for i in query:
  l=i[0]-1
  r=i[1]-1
  print(sum(ac[l:r]))

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 l, r in lr:
  txt = s[l-1:r]
  #print(txt)
  print(txt.count("AC"))

Submission status: Time Limit Exceeded

Solution code:
cho,N = map(int,input().split())
moji = str(input())
for i in range(int(N)):
    s,g = map(int,input().split())
    cmoji = moji[s-1:g]
    print(cmoji.count('AC'))

Submission status: Time Limit Exceeded

Solution code:
n, q = map(int, input().split())
s = input()
ls = [list(map(int, input().split())) for i in range(q)]
d = []
pre = 0
c = 0

for i in range(len(s)-1):
    if s[i:i+2] == 'AC':
        d.append(True)
    else:
        d.append(False)

for start, end in ls:
    ans = sum(d[start-1:end-1])
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(Q):
    line = list(map(int, input().split()))
    dl.append(line[0])
    dr.append(line[1])

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

ans=[]
for l, r in zip(dl, dr):
    ans.append(s[r]-s[l])

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    # n = int(input())
    n, q = map(int, input().split())
    # a = list(map(int, input().split()))
    s = input()
    # h = [int(input()) for _ in rane(n)]
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        lr.append([l-1, r-1])

    count = [0] * (10 ** 6)
    for i in range(1, n):
        if s[i-1] == "A" and s[i] == "C":
            count[i] = 1

    for i in range(q):
        print(sum(count[lr[i][0]+1:lr[i][1]+1]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cs = []
for i in range(1, 1 + N):
  cs.append(S[:i].count('AC'))

for l, r in ([int(i) for i in input().split()] for _ in range(Q)):
  print(cs[r - 1] - cs[l - 1])

Submission status: Time Limit Exceeded

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

    Q -= 1

Submission status: Time Limit Exceeded

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

    Q -= 1

Submission status: Time Limit Exceeded

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

    Q -= 1

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
while Q:
    l, r = map(int, input().split())
    sub = S[l-1:r]
    ct = sub.count('AC')
    print(ct)
    Q -= 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())
    temp = s[l-1:r]
    res = 0
    for i in range(len(temp)-1):
        if temp[i] == 'A' and temp[i+1] == 'C':
            res += 1
    print(res)

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
for j in range(q):
    l,r = map(int,input().split())
    temp = s[l-1:r]
    res = 0
    i=0
    while i < len(temp)-1:
        if temp[i]=='A' and temp[i+1]=='C':
            res += 1
            i += 2
        else:
            i+=1
    print(res)

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

c = [0]
for i in range(n-1):
  c.append(s[i:i+2]=='AC') 
    
for x in a:
  print(sum(c[x[0]:x[1]]))

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

for x in a:
  cnt = 0
  for i in range(x[0]-1, x[1]-1):
    if s[i:i+2] == 'AC':
      cnt += 1
  print(cnt)

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

for x in a:
  print(s[x[0]-1:x[1]].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())
  print(s[l-1:r].count('AC'))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 00:57:13 2020

@author: liang
"""

N, Q = map(int, input().split())
S = input()
lis = list()
for i in range(len(S) - 1):
    if S[i:i+2] == "AC":
        lis.append(i)
    #print(lis[i:i+2])
#print(lis)
for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    ans = 0
    for t in lis:
        if l <= t < r:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = list(map(int,input().split()))
b = input()
e = []
ans = 0
cnt = 0
for i in range(a[1]):
    c,d=input().split()
    e.append((int(c), int(d)))

for j in range(a[1]):
  for k in range(e[j][0]-1,e[j][1]-1):
    if b[k] == "A" and b[k+1] == "C":
      cnt += 1
      ans = max(ans,cnt)
  cnt = 0
  print(ans)
  ans = 0

Submission status: Time Limit Exceeded

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


for i in range(q):
  cnt=0
  for j in range(l[i][0]-1,l[i][1]-1):
    if s[j]=='A' and s[j+1]=='C':
      cnt+=1
  print(cnt)

Submission status: Time Limit Exceeded

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


for i in range(q):
  cnt=0
  a=l[i][0]-1
  b=l[i][1]
  p=s[a:b]
  for j in range(len(p)-1):
    if p[j]=='A' and p[j+1]=='C':
      cnt+=1
  print(cnt)

Submission status: Time Limit Exceeded

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

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    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())
        ans = 0
        for idx in ac_idx:
            if idx >= r-1:
                break
            elif idx >= l-1:
                ans += 1
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

def main():
    N, Q = map(int, input().split())
    S = input().rstrip()
    ac_flag = []
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            ac_flag.append(1)
        else:
            ac_flag.append(0)
    for _ in range(Q):
        l, r = map(int, input().split())
        print(sum(ac_flag[l-1:r-1]))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# author:  Taichicchi
# created: 12.09.2020 19:26:19

import sys

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

S = input()

cum_ls = []


def cnt_ac(s):
    cnt = 0
    for i in range(N - 1):
        if s[i:i + 2] == "AC":
            cnt += 1
    return cnt


for i in range(N):
    cum_ls.append(cnt_ac(S[:i + 1]))

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

Submission status: Time Limit Exceeded

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

count = [0] * N

for i in range(N-1):
	
	if S[i] == 'A' and S[i+1] == 'C':
		count[i] = 1


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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = list(map(str,input()))
lr = [0] * (len(s)-1)

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

for i in range(q):
    st,fn = map(int,input().split())
    tmp = lr[st-1:fn-1]
    print(sum(tmp))

Submission status: Time Limit Exceeded

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


for i in range(q):
    ans = 0
    st = lr[i][0]-1
    f = lr[i][1]-1
    for j in range(st,f):
        if s[j] == "A" and s[j+1] == "C":
            ans += 1  
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import re

def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, q = Input()
    s = input()
    questions = [Input() for _ in range(q)]

    for l, r in questions:
        l -= 1
        s_i = s[l:r]
        replaced_s = re.sub("AC", "", s_i)
        print((len(s_i)-len(replaced_s))//2)

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split())
n = input()
for i in range(b):
  s,t=map(int,input().split())
  count=0
  for j in range(s-1,t-1):
    if n[j:j+2]=="AC":
      count+=1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
c = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        c[i] = 1
for i in range(Q):
    l,r = map(int,input().split())
    ans = c[l-1:r-1]
    print(ans.count(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())
    c = 0
    for j in range(l-1,r-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 = list(input())
for i in range(Q):
    l,r = map(int,input().split())
    c = 0
    for j in range(l-1,r-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 = list(input())
for i in range(Q):
    l,r = map(int,input().split())
    s = S[l-1:r]
    c = 0
    for j in range(len(s)-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 = list(input())
for i in range(Q):
    l,r = map(int,input().split())
    s = "".join(S[l-1:r])
    print(s.count("AC"))

Submission status: Time Limit Exceeded

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

rui=[0]*(n+1)
for i in range(len(s)+1):
  rui[i] = s[0:i].count('AC')

for i in range(q):
  print(rui[lr[i][1]] - rui[lr[i][0]])

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,Q = map(int,input().split())
S = input()
lr = [map(int,input().split()) for _ in range(Q)]
l_r = [list(i) for i in zip(*lr)] 

scc = list(itertools.accumulate(S))

for i in range(Q):
    right = scc[l_r[1][i]-1]
    left = right[l_r[0][i]-1:]
    print(left.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())
    print(s[l - 1:r].count("AC"))

Submission status: Time Limit Exceeded

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

F=[0]*len(S)
for i in range(N):
    if S[i:i+2]=='AC':
        F[i]=1
for l,r in LR:
    print(sum(F[l-1:r-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 l,r in LR:
    tmp=S[l-1:r]
    ans=0
    for i in range(len(tmp)-1):
        #print(tmp, tmp[i:i+2])
        if tmp[i:i+2]=='AC':
            ans+=1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, Q = map(int, input().split())
S = input()
t = S.count('AC')
L = []
R = []
for i in range(N):
    L.append(S[:i].count('AC'))
    R.append(S[i:].count('AC'))
for i in range(Q):
    l, r = map(int, input().split())
    print(t-L[l]-R[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()
for i in range(Q):
  l, r = map(lambda x: int(x)-1, input().split())
  ans = 0
  for i in range(l, r):
    if S[i] == "A" and S[i+1] == "C":
      ans += 1
  print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,q = map(int,input().split())
s = input()
a = []
for i in range(q):
    a.append(list(map(int,input().split())))
for i in range(q):
    if 'AC' in s[a[i][0]-1:a[i][1]]:
        ans = s[a[i][0]-1:a[i][1]].count('AC')
        print(ans)
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
# https://note.nkmk.me/python-list-common/
def f(l,r,myList):
    chkList = [int(i) for i in range(l,r)]
    com_List = set(chkList) & set(myList)
    return len(com_List)

n,q = map(int,input().split())
s = str(input())
memo = []
for i in range(n-1):
    #print(s[i:i+2])
    if s[i:i+2]=='AC':
        memo.append(i+1)
        i += 1
#print(s)
#print(memo)
for i in range(q):
    l,r = map(int,input().split())
    print(f(l,r,memo))

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

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

for j in range(Q):
  l,r = map(int,input().split())
  cnt = 0
  for k in AC:
    if l < k < r:
      cnt += 1
    if r < k:
      break
  print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,Q = map(int,input().split())
S = input()
AC = []
for i in range(N-1):
  if S[i]+S[i+1] == "AC":
    AC.append(i+1.5)

for j in range(Q):
  l,r = map(int,input().split())
  cnt = 0
  for k in AC:
    if l < k < r:
      cnt += 1
    if r < k:
      break
  print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,q=input2()
B=str(input())
LR=[input_array() for _ in range(q)]

# E=["A","C","G","T"]

for lr in LR:
	st=lr[0]-1
	fi=lr[1]
	print(B[st:fi].count("AC"))

Submission status: Time Limit Exceeded

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