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: Accepted

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

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

Submission status: Accepted

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

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

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

    ans = SS[r-1] - SS[l-1]
    print(ans)

Submission status: Accepted

Solution code:
N, Q = map(int, input().split())
s = input()
X = [0] * N
for i in range(1, N):
    X[i] = X[i-1] + (1 if s[i-1:i+1] == "AC" else 0)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import atexit
import io
import sys

buff = io.BytesIO()
sys.stdout = buff


@atexit.register
def write():
    sys.__stdout__.write(buff.getvalue())

n,q = map(int, raw_input().split())
s = raw_input()
suff = [0 for i in xrange(n+1)]
for i in xrange(n):
	suff[i+1] = suff[i]
	if i > 0 and s[i] == 'C' and s[i-1] == 'A':
		suff[i+1] += 1
for i in xrange(q):
	l,r = map(int, raw_input().split())
	print suff[r] - suff[l]

Submission status: Accepted

Solution code:
n,q=map(int,input().split())
s=str(input())
arr=[0]
count=0
i=1
while(i<n):
	if(s[i-1]=='A' and s[i]=='C'):
		count+=1
	arr.append(count)
	i+=1
ansarr=[]
for i in range(q):
	a,b=map(int,input().split())
	ansarr.append(arr[b-1]-arr[a-1])
print(*ansarr)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
N, Q = map(int, readline().split())
S = readline()
D = [0]*(N+1)
for i in range(N-1):
    D[i+1] = D[i] + (S[i] == 'A' and S[i+1] == 'C')
D[N] = D[N-1]
ans = []
for i in range(Q):
    l, r = map(int, readline().split())
    if S[r-1] == 'A':
        r -= 1
    ans.append("%d\n" % (D[r] - D[l-1]))
sys.stdout.writelines(ans)

Submission status: Accepted

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

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

for l,r in qs:
    print(cums[r] - cums[l])

Submission status: Accepted

Solution code:
from itertools import accumulate

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

calc = [0] * n
prev = None
for i, c in enumerate(s):
    if prev == 'A' and c == 'C':
        calc[i] = 1
    prev = c
calc = [0] + list(accumulate(calc))

ans = []
for _ in range(q):
    l, r = list(map(int, input().split()))
    ans.append(calc[r] - calc[l])
print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
N, Q = map(int, input().split())
S = input()
d = [0] * N
for i in range(N - 1):
    if S[i:i + 2] == 'AC':
        d[i + 1] += 1

for i in range(1, N):
    d[i] += d[i - 1]

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

Submission status: Accepted

Solution code:
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
from heapq import heappush, heappop, heapify
import sys
stdout = sys.stdout
rr = lambda: input().strip()
rri = lambda: int(rr())
rrm = lambda: list(map(int, rr().split()))

from itertools import groupby
def solve(L, R):
    if L == R: return 0
    L-=1;R-=1
    
    return P[R+1] - P[L+1]

N, Q = rrm()
S = rr()
queries = [rrm() for _ in range(Q)]
# preprocess
P = [0]
for i, c in enumerate(S):
    x = +(c == 'C' and i > 0 and S[i-1] == 'A')
    P.append(P[-1] + x)

#print(P)

for L, R in queries:
    print(solve(L, R))

Submission status: Accepted

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

L = [0] * N

f = 0
cnt = 0
for i in range(len(S)):
  if S[i] == "A":
    f = 1
  elif S[i] == "C":
    if f == 1:
      cnt += 1
      f = 0
  else:
    f = 0
  L[i] = cnt


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

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        a.append(a[l]+1)
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        for j in range(1,3):
            a.append(a[l]+1)
        l+=1
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
a=[0]
for l in range(n):
    if s[l]=='A' and s[l+1]=='C':
        for j in range(1,2):
            a.append(a[l]+1)
        l+=1
    else :
        a.append(a[l])
for k in range(q):
    x,y=map(int,input().split())
    print(a[y-1]-a[x-1])
print(a)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
moji = str(input())
ans = [0]
for i in range(N-1):
    if moji[i] == "A" and moji[i+1] == "C":
        ans.append(ans[i]+1)
    else:
        ans.append(ans[i])

        
for i in range(K):
    st,sp = map(int,input().split())
    print(ans[sp]-ans[st])

Submission status: Runtime Error

Solution code:
cho,N = map(int,input().split())
moji = str(input())
moji_dict = []
flg = 0
##計算量は10**5
for i in range(cho):
    if flg == 1:
        flg = 0
    elif i != cho and moji[i] == "A" and moji[i+1] =="C":
        moji_dict.append(i + 1)
        flg = 1
##計算量は10**3　* 10 ** 5
for j in range(N):
    s,g = map(int,input().split())
    print(len([k for k in moji_dict if k >= s and k < g]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ac_list = [0]*n

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

for l, r in lr:
    l -= 1
    r -= 1
    print(ac_list[l:r].count(1))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    n,q = map(int, input().split())
    s = input().rstrip()
    t = [0]*(n+1)
    for _ in range(n):
        if s[i:i+2] == "AC":
            t[i+1] = t[i] + 1

    for i in range(q):
        l,r = map(int, input().split())
        prin(t[r-1] - t[l-1])

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
cnt = 0
for i in range(1, N):
    if S[-i] == "C" and S[-i-1] == "A":
            cnt += 1
    dp[N-i] = cnt
print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
dp = [0] * (N + 2) #i文字目から何個ACがあるか
for i in range(1, N + 1):
    dp[i] = S[i:].count("AC")
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = " " + input()
l = []
r = []
for _ in range(Q):
    _l, _r = map(int, input().split())
    l.append(_l)
    r.append(_r)
#CofAC= [-1] * (N + 1) #ACのC部分が何文字目か記録
#print([i for i, x in enumerate(l_dup) if x == 'a'])
# [0, 4]
#print([i for i, x in enumerate(S) if x == 'AC'])
dp = [0] * (N + 2) #i文字目から何個ACがあるか
for i in range(1, N + 1):
    dp[i] = S[i:].count("AC")
#print(dp)
ans = 0
for q in range(Q):
    ans = dp[l[q]] - dp[r[q] + 1]
    if S[r[q]] == "A" and S[r[q] + 1] == "C":
        ans -= 1
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a =s[0]
for i in range(n):
    b = a
    a = s[i]
    if b+a=='AC':
        s_ps.append(i)
#print(s_ps)
len_s = len(s_ps)


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,Q = map(int,input().split())
S = input()
X = [list(map(int, input().split())) for _ in range(Q)]
L =[0]*(N+1)
for i in range(N):
  if S[i]=="A" and S[i+1]=="C":
    L[i+1] = L[i]+1 
  else:
    L[i+1] = L[i]
for x in X:
  print(L[x[1]-1]-L[x[0]-1])

Submission status: Runtime Error

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

c=0
C=[]
for i in range(n):
    if s[i]=="A":
        p=1
    elif p==1 and s[i]=="C":
        c+=1
        p=0
    else:
        p=0
    C.append(c)

for i in range(q):
    l=LR[i][0]
    r=LR[i][1]
    ans = C[r-1]-C[l-1]
    print(ans)

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
c=[]
for i in range(n-1):
  if s[i]=="A":
    if s[i+1]=="C"
      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: Runtime Error

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

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

index = [i for i, x in enumerate(S) if S[i] == "A" and S[i + 1] == "C"]

for i in range(Q):
    count = 0
    for j in index:
        if l[i]-1 <= j and j < r[i] and j + 1 < r[i]:
            count += 1
    
    print(count)

Submission status: Runtime Error

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

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

index = [i for i, x in enumerate(S) if S[i] == "A" and S[i + 1] == "C"]

for i in range(Q):
    count = 0
    for j in index:
        if l[i]-1 <= j and j < r[i]-1:
            count += 1
    
    print(count)

Submission status: Runtime Error

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[j + 1] == "C":
            count += 1
    print(count)

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
    t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
    for i in range(Q):
        l, r = map(int, input().split())
        print(t[r-1] - t[l-1])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy

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

cnt = [0]
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'C':
        cnt.append(cnt[-1] + 1)
    else:
        cnt.append(cnt[-1])

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s = input()

t = []

for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        t.append(1)
    else:
        t.append(0)
        
for i in range(q):
    a,b = map(int,input().split())
    print(sum(t[a-1:b-1]))

Submission status: Runtime Error

Solution code:
n, q = list(map(int, input().split()))
s = list(input())
lr = [list(map(int, input().split())) for i in range(q)]
ac = [0] * 10 ** 5
for i in range(n):
    if i < n:
        if s[i] == "A" and s[i + 1] == "C":
            ac[i + 1] = 1
for i in range(q):
    print(ac[lr[i][0] : lr[i][1]].count(1))

Submission status: Runtime Error

Solution code:
N,Q = (int(X) for X in input().split())
S = input()
AIndex = [Ind for Ind,Str in enumerate(S) if S[Ind:Ind+2]=='AC']
if len(AIndex)==0:
    print('\n'.join(['0']*Q))
else:
    CIndex = [X+1 for X in AIndex]
    for T in range(0,Q):
        L,R = (int(X) for X in input().split())
        LN = [(L-1)<=X for X in AIndex].index(True)
        RN = len(CIndex)-[(R-1)>=X for X in CIndex][::-1].index(True)
        print(RN-LN)

Submission status: Runtime Error

Solution code:
N,Q = (int(X) for X in input().split())
S = input()
AIndex = [Ind for Ind,Str in enumerate(S) if S[Ind]=='A' and S[Ind+1]=='C']
CIndex = [X+1 for X in AIndex]
for T in range(0,Q):
    L,R = (int(X) for X in input().split())
    LIndex = [(L-1)<=X for X in AIndex]
    RIndex = [(R-1)>=X for X in CIndex]
    print(sum([X and Y for X,Y in zip(LIndex,RIndex)]))

Submission status: Runtime Error

Solution code:
import copy

N, Q = map(int, input().split())
S = input()
t = [0]*N
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

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

Submission status: Runtime Error

Solution code:
import copy

N, Q = map(int, input().split())
S = input()
ANSlist = [0]*Q
for i in range(Q):
    l ,r = map(int, input().split())
    SS = copy.copy(S)
    SS[l:r]
    for j in range(len(SS)):
        if SS[j] == "A" and SS[j+1] == "C":
            ANSlist[i] += 1
    
for i in range(len(ANSlist)):
    print(ANSlist[i])

Submission status: Runtime Error

Solution code:
import copy

N, Q = map(int, input().split())
S = input()
for i in range(Q):
    l ,r = map(int, input().split())
    SS = copy.copy(S)
    SS[l:r]
    ANS = 0
    for j in range(len(SS)):
        if SS[j] == "A" and SS[j+1] == "C":
            ANS += 1
    
    print(ANS)

Submission status: Runtime Error

Solution code:
import copy

N, Q = map(int, input().split())
S = int(input())
for i in range(Q):
    l ,r = map(int, input().split())
    SS = copy.copy(S)
    SS[l:r]
    ANS = 0
    for j in range(len(SS)):
        if SS[j] == "A" and SS[j+1] == "C":
            ANS += 1
    
    print(ANS)

Submission status: Runtime Error

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

for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    cnt += 1
    li.append(cnt)
  else:
    li.append(cnt)

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
N,Q = list(map(int,input().split()))
s = input()
lis=[0]*N
 
count = 0
for i in range(1,len(s)):
    if s[i-1] == 'A' and s[i] == 'C':
        count +=1
    lis[i]+=count
for i in range(Q):
    l,r = list(map(int,input().split()))
    print(lis[r-1]-lis[l-1])

Submission status: Runtime Error

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

ss()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
for i in range(N):
    a,b=map(int,input().split())
    print(S[a-1:b-1].replace('AC','0').count('0'))

Submission status: Runtime Error

Solution code:
N,Q=map(int,input().split())
S=input()
for i in range(N):
    a,b=map(int,input.split())
    print(S[a-1:b-1].replace('AC','0').count('0'))

Submission status: Runtime Error

Solution code:

N, Q = map(int, input().split())
S = input().rstrip('\n')
count = [0]*(N+2)

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

#累積和
for i in range(1, N+1):
    count[i] += count[i-1]

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

Submission status: Runtime Error

Solution code:

N, Q = map(int, input().split())
S = input().rstrip('\n')
count = [0]*(N+1)

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

#累積和
for i in range(1, N+1):
    count[i] += count[i-1]

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

Submission status: Runtime Error

Solution code:
N, Q = map(int,input().split())
S = input()
#'AC'が見つかったらCのほうに+1
count = [0]*(N+1)
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "C":
            count[i+1] += count[i] + 1
        else:
            count[i+1] = count[i]
    else:
        count[i+1] = count[i]
    
#print(count)

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

Submission status: Runtime Error

Solution code:
n,q = map(int,raw_input().split(' '))
s = raw_input()
dp = [0] * len(s)
for j in range(len(s)):
	if s[j-1:j+1] == 'AC':dp[j] = 1 + (dp[j-2] if j-2 >= 0 else 0)

for _ in range(q):
	u,v = map(int, raw_input().split(' '))
    print dp[v-1] - (dp[u-2] if u-2 >= 0 else 0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from itertools import permutations

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, Q = mi()
    S = input()
    lr = [map(int, input().split()) for _ in range(Q)]
    l, r = [list(i) for i in zip(*lr)]

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

    for i in range(Q):
        ans = dp[r[i]]-dp[l[i]]
        if S[l[i-2]:l[i]] == 'AC':
            ans -= 1
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

numbers = []
for i in range(n-1):
    if s[i]+s[i+1] == "AC":
        numbers.append(i+1)
for l,r in lr:
    x,y = bisect_left(numbers, l), bisect_right(numbers, r)
    if numbers[y-1]+1 <= r:print(y-x)
    else: print(y-x-1)

Submission status: Runtime Error

Solution code:
import numpy as np
N, Q=map(int,input().split())
S=input()
L =[list(map(int,input().split()))for i in range(Q)]
c = [0]*(N)  #ACのチェック
s = [0]*(N)  #ACの累積和
ans = [0]*Q 

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    c[i+1] = 1
s = np.cumsum(c)
for i in range(Q):
  ans[i] = s[L[i][1]-1]-s[L[i][0]-1]

for i in ans:
  print(i)

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, Q = map(int, readline().split())
    S = list(readline_s().rstrip())
    ac_check = [0] * (N)
    tsum = [0] * (N + 1)

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

    for i in range(N):
        tsum[i + 1] += tsum[i]

    ans = []
    for i in range(Q):
        l, r = map(int, readline().split())
        count = tsum[r] - tsum[l - 1]
        if ac_check[l - 1] == 2:
            count -= 1
        ans.append(count)

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readline_s = sys.stdin.readline
readlines = sys.stdin.buffer.readlines


def main():
    N, Q = map(int, readline().split())
    S = list(readline_s().rstrip())
    ac_check = [0] * (N)
    tsum = [0] * (N + 1)

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

    for i in range(N):
        tsum[i + 1] += tsum[i]

    # print(tsum)
    # print(ac_check)

    ans = []
    for i in range(Q):
        l, r = map(int, readline().split())
        count = tsum[r] - tsum[l - 1]
        if ac_check[l - 1] == 2:
            count -= 1
        ans.append(count)

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


z=[0]*n
count=0
for i in range(n):
    z[i]=count
    if s[i]=="A":
        if s[i+1]=="C":
            count+=1
            z[i]+=1

for i in range(q):
    l, r =map(int,input().split())
    #r文字目までのACの数-(l-1)文字目まで
    if l==1:
        ans=z[r-1]
    elif r-l==1:
        if s[l-1]=="A" and s[l]=="C":
            ans=1
        else:
            ans=0
    else:
        ans=z[r-2]-z[l-2]
    print(ans)

Submission status: Runtime Error

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


z=[0]*n
count=0
for i in range(n):
    z[i]=count
    if s[i]=="A":
        if s[i+1]=="C":
            count+=1
            z[i]+=1

for i in range(q):
    l, r =map(int,input().split())
    #r文字目までのACの数-(l-1)文字目まで
    if l==1:
        ans=z[r-1]
    elif r-l==1:
        if s[l-1]=="A" and s[l]=="C":
            ans=1
        else:
            ans=0
    else:
        ans=z[r-1]-z[l-2]
    print(ans)

Submission status: Runtime Error

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())
c = [0]*(len(s)+1)
for i in range(len(s)):
	if s[i] == 'A' and s[i+1] == 'C':
		c[i+1] += c[i] + 1
	else:
		c[i+1] = c[i]
for i in range(q):
	print(c[r[i]-1]-c[l[i]-1])

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
st=input()
ssum=[0,0]
for i in range(1,n):
    if st[i-1]=="A" and st[i]=='C':
        ssum.append(ssum[-1]+1)
    else:
        ssum.append(ssum[-1])

for i in range(q):
    a,b=map(int,input().split())
    print(ssum[b+1]-ssum[a])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = str(input())
a = [0]
for i in range(1,n):
    if s[i-1] == "A":
        if s[i] == "C":
            a.append(a[-1]+1)
    else:
        a.append(a[-1])
for j in range(q):
    u,t = map(int,input().split())
    print(a[t-1]-a[u-1])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = str(input())
ls = [list(map(int,input().split())) for _ in range(q)]
a = [0]
for i in range(1,n):
    if s[i-1] == "A":
        if s[i] == "C":
            a.append(a[-1]+1)
    else:
        a.append(a[-1])
for j in range(q):
    (u,t) = (ls[j][0],ls[j][1])
    print(a[t-1]-a[u-1])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = str(input())
ls = [list(map(int,input().split())) for _ in range(q)]
a = [0]
for i in range(1,n):
    if s[i-1] == "A":
        if s[i] == "C":
            a.append(a[-1]+1)
    else:
        a.append(a[-1])
print(a)
for j in range(q):
    (u,t) = (ls[j][0],ls[j][1])
    print(a[t-1]-a[u-1])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = str(input())
ls = [list(map(int,input().split())) for _ in range(q)]
c = 0
a = [0]
for i in range(1,n):
    if s[i-1] == "A":
        if s[i] == "C":
            a.append(a[-1]+1)
    else:
        a.append(a[-1])
for j in range(q):
    (u,t) = (ls[j][0],ls[j][1])
    print(a[t-1]-a[u-1])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = str(input())
ls = [list(map(int,input().split())) for _ in range(q)]
c = 0
a = [0]
for i in range(1,n):
    if s[i-1] == "A":
        if s[i] == "C":
            a.append(a[i-1]+1)
    else:
        a.append(a[i-1])
for j in range(q):
    (u,t) = (ls[j][0],ls[j][1])
    print(a[t-1]-a[u-1])

Submission status: Runtime Error

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

for i in range(len(s)-1):
  if s[i]+s[i+1] == 'AC':
    lis[i],lis[i+1] = 0.5,0.5
    

for j in range(q):
  l,r = map(int,input().split())
  su = sum(lis[l-1:r])
  if lis[l-1] == 0.5 and lis[l-2] == 0.5 and lis[r-1] == 0.5 and lis[r]==0.5:
    su -= 1
  print(int(su))

Submission status: Runtime Error

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

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

for i in range(Q):
    L, R = int(query[i][0]), int(query[i][1])
    if S[R-1] == 'A':
        print(sum(AC[L-1:R-1]))
    else:
        print(sum(AC[L-1:R]))

Submission status: Runtime Error

Solution code:
import itertools

N,Q = map(int, input().split())
S = input()
a = list(itertools.accumulate([i for i in S]))

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