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()
ls = [list(map(int, input().split())) for i in range(q)]
d = [0]
pre = 0
c = 0

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

print(d)

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

Submission status: Wrong Answer

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)
print(t)
for i in range(Q):
    l,r = map(int, input().split())
    print(t[r-1] - t[l-1])

Submission status: Wrong Answer

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

    Q -= 1

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
t=[0 for _ in range(len(s)+1)]
for i in range(n):
  t[i+1]=t[i]+(i 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: Wrong Answer

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

@author: liang
"""

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

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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):
        print(0)

        
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
con=[0]
c=False
for i in range(n):
    if s[i]=='A':
        c=True
        con.append(con[-1])
        continue
    if c:
        if s[i]=='C':
            con.append(con[-1]+1)
            c=False
            continue
        else:
            con.append(con[-1])
            c=False
            continue
    con.append(con[-1])
    c=False
for j in range(q):
    l,r=map(int,input().split())
    if s[l-1]=='C':
        print(max(0,con[r]-con[l-1]-1))
        continue
    print(max(0,con[r]-con[l-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
li=[0]
A=False
ans=0
import copy
for i in range(N):
    if A==True:
        if S[i]=="C":
            ans+=1
        A=False
    else:
        if S[i]=="A":
            A=True
    li.append(copy.copy(ans))

for j in range(Q):
    a,b=map(int,input().split())
    print(li[b]-li[a])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
A = []
for i in range(N - 1):
  if S[i] == "A" and S[i+1] == "C":
    A.append(i+1)
lA = len(A)
for i in range(Q):
  l, r = map(int, input().split())
  L1 = 0
  R1 = lA
  while L1 + 1 < R1:
    C1 = (L1 + R1) // 2
    if A[C1] < l:
      L1 = C1
    else:
      R1 = C1
  L2 = 0
  R2 = lA
  while L2 + 1 < R2:
    C2 = (L2 + R2) // 2
    if A[C2] < r:
      L2 = C2
    else:
      R2 = C2
  print(L2 - L1)

Submission status: Wrong Answer

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)

print(AC)

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

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

Submission status: Wrong Answer

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
cnt = 0

for i in range(N-1):
    if S[i:i+2] == 'AC':
        c[i+1]=c[i]+1
    else:
        c[i+1]=c[i]
    #c[i] = S[:i].count('AC')
    #countを使わずにiまでの合計値をリスト化

print(c)

for i,j in zip(l,r):
    #print(sum(c[:j])-sum(c[:i]))
    #l,r = map(int,input().split())
    print(c[j-1]-c[i-1])
    #合計値を利用してsumを使わずに差を表示して計算減させる
    #リストを要素ごとに分けるのは初めにやっておいて大丈夫

Submission status: Wrong Answer

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
cnt = 0

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

print(c)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if ac == []:
    for i in range(q):
        print(0)
    exit()

for l, r in lr:
    l -= 1
    r -= 1
    li = bisect_left(ac, l)
    ri = bisect_right(ac, r)
    if r > ac[ri-1]:
        print(ri-li)
    else:
        print(ri-li-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a =s[0]

for i in range(n):
    b = a
    a = s[i]
    if b+a=='AC':
        s_ps[i]=1
        
#print(s_ps)


for _ in range(q):
    r,l=list(map(int, input().split()))
    #print(s_ps[r-1:l])
    print(sum(s_ps[r-1:l]))

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
num=[0]
be=""

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

Submission status: Wrong Answer

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

# dp[i][1]:i文字目が'A'で先頭からi文字目までの部分列に含まれる'AC'の数
dp=[[False, 0] for _ in range(N+1)]
for i in range(1,N+1):
    if S[i-1]=='A':
        dp[i][0]=True
        dp[i][1]=dp[i-1][1]
    elif S[i-1]=='C':
        dp[i][1]=dp[i-1][1]+int(dp[i-1][0])
    else:
        dp[i][1]=dp[i-1][1]
# print(dp)

# L=[[0]*2 for _ in range(N)]
for i in range(Q):
    l,r=list(map(int, input().split()))
    if l==r:
        print(0)
    else:
        l-=1
        print(dp[r][1]-dp[l][1]-int(dp[l][0]*(1-dp[l+1][0])))

Submission status: Wrong Answer

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

# dp[i][1]:i文字目が'A'で先頭からi文字目までの部分列に含まれる'AC'の数
dp=[[False, 0] for _ in range(N+1)]
for i in range(1,N+1):
    if S[i-1]=='A':
        dp[i][0]=True
        dp[i][1]=dp[i-1][1]
    elif S[i-1]=='C':
        dp[i][1]=dp[i-1][1]+int(dp[i-1][0])
    else:
        dp[i][1]=dp[i-1][1]
print(dp)

# L=[[0]*2 for _ in range(N)]
for i in range(Q):
    l,r=list(map(int, input().split()))
    if l==r:
        print(0)
    else:
        l-=1
        print(dp[r][1]-dp[l][1]-int(dp[l][0]*(1-dp[l+1][0])))

Submission status: Wrong Answer

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

# dp[i][1]:i文字目が'A'で先頭からi文字目までの部分列に含まれる'AC'の数
dp=[[False, 0] for _ in range(N+1)]
for i in range(1,N+1):
    if S[i-1]=='A':
        dp[i][0]=True
        dp[i][1]=dp[i-1][1]
    elif S[i-1]=='C':
        dp[i][1]=dp[i-1][1]+int(dp[i-1][0])
    else:
        dp[i][1]=dp[i-1][1]
# print(dp)

# L=[[0]*2 for _ in range(N)]
for i in range(Q):
    l,r=list(map(int, input().split()))
    l-=1
    print(dp[r][1]-dp[l][1]-int(dp[l][0]*(1-dp[l+1][0])))

Submission status: Wrong Answer

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

# dp[i][1]:i文字目が'A'で先頭からi文字目までの部分列に含まれる'AC'の数
dp=[[False, 0] for _ in range(N+1)]
for i in range(1,N+1):
    if S[i-1]=='A':
        dp[i][0]=True
        dp[i][1]=dp[i-1][1]
    elif S[i-1]=='C':
        dp[i][1]=dp[i-1][1]+int(dp[i-1][0])
    else:
        dp[i][1]=dp[i-1][1]
print(dp)

# L=[[0]*2 for _ in range(N)]
for i in range(Q):
    l,r=list(map(int, input().split()))
    l-=1
    print(dp[r][1]-dp[l][1]-int(dp[l][0]*(1-dp[l+1][0])))

Submission status: Wrong Answer

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

# dp[i][1]:i文字目が'A'で先頭からi文字目までの部分列に含まれる'AC'の数
dp=[[False, 0] for _ in range(N+1)]
for i in range(1,N+1):
    if S[i-1]=='A':
        dp[i][0]=True
        dp[i][1]=dp[i-1][1]
    elif S[i-1]=='C':
        dp[i][1]=dp[i-1][1]+int(dp[i-1][0])
    else:
        dp[i][1]=dp[i-1][1]
# print(dp)

# L=[[0]*2 for _ in range(N)]
for i in range(Q):
    l,r=list(map(int, input().split()))
    l-=1
    print(dp[r][1]-dp[l][1]-int(dp[l][0]))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Solution code:
n,q=map(int,input().split())
s=list(input())
ac=[0]*n
for i in range(1,n):
  ac[i]=ac[i-1]
  if s[i-1]+s[i]=='AC':
    ac[i]+=1
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 i in range(Q)]

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

print(countList)

for i in range(Q):
    l = lr[i][0]
    r = lr[i][1]
    lCount = countList[l - 1]
    rCount = countList[r - 1]
    print(rCount - lCount)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right


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 = []
    A_pos = []
    C_pos = []
    for i in range(n - 1):
        if S[i] == 'A' and S[i + 1] == 'C':
            A_pos += [i]
            C_pos += [i + 1]
    for i in range(q):
        l, r = nm()
        ans += [bisect_right(C_pos, r) - bisect_right(A_pos, l) + 1]
    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,Q = MI()
S = LS2()
A = [0]*N

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

from itertools import accumulate

A = list(accumulate(A))
print(A)
for i in range(Q):
    l,r = MI()
    print(A[r-1]-A[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
qn = [list(map(int, input().split())) for _ in range(Q)]
S = "0" + S
cnt = []
cnt.append(0)
for i in range(1, N+1):
    if (S[i-1:i+1] == "AC"):
        cnt.append(cnt[i-1] + 1)
    else:
        cnt.append(cnt[i-1])
for q in qn:
    ans = cnt[q[1]] - cnt[q[0]-1]
#    if S[q[0]-1:q[0]+1] == "AC":
#        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
#! python3
#  solve_122C.py

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

l = [0]*N #ACの内Aの番号を格納(?番目形式)
ans = 0

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

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

Submission status: Wrong Answer

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

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

print(L)

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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(indices)
for i in range(Q):
  l,r=lr[i]
  print(indices[r-1]-indices[l-1])

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

cnt = [0] * (n)
for i in range(0, n - 1):
    if s[i] == 'A' or s[i + 1] == 'C':
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]

for i in range(q):
    ll = lr[i][0] - 1
    rr = lr[i][1] - 1
    print(cnt[rr] - cnt[ll])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

cnt = [0] * (n)
for i in range(0, n - 1):
    if s[i] == 'A' or s[i + 1] == 'C':
        cnt[i + 1] = cnt[i] + 1
    else:
        cnt[i + 1] = cnt[i]

for i in range(q):
    ll = lr[i][0] - 1
    rr = lr[i][1] - 1
    print(cnt[rr] - cnt[ll])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

cum = [0]*(n+1)
pre = s[0]
cnt=0
for i in range(1,n):
    now = s[i]
    if pre=="A" and now=="C":
        cnt+=1
    cum[i+1] = cnt
for l,r in lr:
    print(cum[r]-cum[l])

Submission status: Wrong Answer

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.deepcopy(S)
    print(SS)
    SS = SS[l-1:r]
    print(SS)
    for j in range(1,len(SS)):
        if SS[j] == "C" and SS[j-1] == "A":
            ANSlist[i] += 1
    
for i in range(len(ANSlist)):
    print(ANSlist[i])

Submission status: Wrong Answer

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

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

dp = [0]*N
for j in range(N-1):
  if S[j]=='A' and S[j+1]=='C':
    dp[j+1] = dp[j]+1
  else:
    dp[j+1] = dp[j]

print(dp)
for k in range(Q):
  print(dp[R[k]-1]-dp[L[k]-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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-1].replace('AC','0').count('0'))

Submission status: Wrong Answer

Solution code:
import bisect
def main():
    N, Q = map(int, input().split())
    S = input()
    ll = []
    t = 10**6
    for i, v in enumerate(S):
        if v == 'A':
            t = i
        elif v == 'C':
            if t < i:
                ll.append(t)
                ll.append(i)
                t = 10**6
    for _ in range(Q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        li = bisect.bisect_left(ll, l)
        ri = bisect.bisect_right(ll, r)
        if li % 2 == 1:
            li += 1
        if ri % 2 == 1:
            ri -= 1
        print((ri-li)//2)
main()

Submission status: Wrong Answer

Solution code:
import bisect
def main():
    N, Q = map(int, input().split())
    S = input()
    ll = []
    t = 10**6
    for i, v in enumerate(S):
        if v == 'A':
            t = i
        elif v == 'C':
            if t < i:
                ll.append(t)
                ll.append(i)
                t = 10**6
    for _ in range(Q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        li = bisect.bisect_left(ll, l)
        ri = bisect.bisect_right(ll, r)
        if li % 2 == 1:
            li += 1
        print((ri-li)//2)
main()

Submission status: Wrong Answer

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

ac_cnts = [0]*(n)
curr_cnt = 0
for i, (s1,s2) in enumerate(zip(s[:-1],s[1:])):
    if s1 == 'A' and s2 == 'C':
        curr_cnt += 1
    ac_cnts[i+1] = curr_cnt

ans = []
for _ in range(q):
    l,r = map(int, input().split())
    l-=1
    r-=1
    ans.append(ac_cnts[r]-ac_cnts[l])

print(ac_cnts)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

T = []
count = 0
idx = 0
for s in S:
    if s =='C' and idx ==1:
        idx = 0
        count += 1
    elif s =='A':
        idx = 1
    T.append(count)
q = []
for _ in range(Q):
    l,r = map(int,input().split())
    q.append([l,r])
for l,r in q:
    print(T[r-1]-T[l-1])

Submission status: Wrong Answer

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

T = [0]
count = 0
idx = 0
for s in S:
    if s =='C' and idx ==1:
        idx = 0
        count += 1
    elif s =='A':
        idx = 1
    T.append(count)
q = []
for _ in range(Q):
    l,r = map(int,input().split())
    q.append([l,r])
for l,r in q:
    print(T[r]-T[l])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

array = [0]*len(s)

for i in range(1,len(s)-1):
  if( s[i-1:i+1] == "AC" ):
    array[i] = array[i-1] + 1
  else:
    array[i] = array[i-1]
      
array[len(s)-1] = array[len(s)-2]

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

Submission status: Wrong Answer

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

array = [0]*len(s)

for i in range(len(s)-1):
  if( s[i-1:i+1] == "AC" ):
    if( i == 0 ):
      array[i] = 1
    else:
      array[i] = array[i-1] + 1
  else:
    if( i == 0 ):
      array[i] = 0
    else:
      array[i] = array[i-1]
      
array[len(s)-1] = array[len(s)-2]

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

Submission status: Wrong Answer

Solution code:
n,q = map(int,raw_input().split(' '))
s = raw_input()
dp = [0] * len(s)
cumul = 0
for j in range(len(s)):
	if s[j-1:j+1] == 'AC': cumul +=1
	dp[j] = cumul 
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: Wrong Answer

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

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

s = list(input())

s_a = [0]*N

ans = 0

for i,v in enumerate(s): #リストのAとCの要素を記憶する
    if v == 'A':
        s_a[i] = 1

for _ in range(Q):
    L,R = map(int,input().split())
    ans += sum(s_a[L-1:R-1])
    print(ans)
    ans = 0

Submission status: Wrong Answer

Solution code:
n,q=map(int,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(int,input().split())
  print(b[r-1]-b[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
B = []
for s in range(len(S)):
    B.append(S[s])
A = []
for q in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    C = []
    C = S[l-1:r]
    for c in range(len(C)-1):
        if C[c] + C[c+1]  == 'AC':
            cnt += 1
    A.append(cnt)
print(A)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

s=[]
s.append(0)

for i in range(1,N):
    if(S[i-1]=='A' and S[i]=='C'):
        print(i)
        s.append(s[i-1]+1)
        print(s)
    else:
        s.append(s[i-1])
print(s)
for i in range(Q):

    l,r=map(int,input().split())

    print(s[r-1]-s[l-1])




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

s=[0 for i in range(N+1)]
s[0]=0

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

for i in range(Q):
    print(s[r[i]]-s[l[i]])
'''

Submission status: Wrong Answer

Solution code:
# 累積和の考え方
#   listに積み重ねた数値を出しておくことで特定範囲の数値を求める時間を短縮する
#   例：ABBBBAABBBBAB があるときに(l,r)にAがいくつ含まれるかを求める場合は以下のように(1長い)listを作る
#      BBABBBAABBBBAA
#      000111123333345
#   このリストの文字列のr-lで出せる(3,7)ならstr[7]-str[3]を出すと3-1で2となる

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

# 累積和のリストを作成
cumsum = [0]*(n+1)
for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        cumsum[i+1]+=cumsum[i]+1
    else:
        cumsum[i+1]=cumsum[i]
cumsum[n] = cumsum[n-1]

for left, right in lr:
    print(cumsum[right]-cumsum[left])