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()
ruisekiwa = [0]
for i in range(len(s)-2):
    if s[i:i+2] == 'AC':
        ruisekiwa += [ ruisekiwa[-1] + 1 ]
    else:
        ruisekiwa += [ ruisekiwa[-1] ]

ruisekiwa += [ ruisekiwa[-1] ]

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

Submission status: Wrong Answer

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

ruisekiwa += [ ruisekiwa[-1] ]

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
list1 = raw_input().split()


String = str(raw_input())

q = int(list1[1])

String = String.replace('AC','aC')
print String

for x in range(q):
    lr_list = []
    str_list = []
    lr_list = raw_input().split()
    print lr_list

    l = int(lr_list[0]) -1
    r = int(lr_list[1]) -1

    string_item = String[l:r]
    print string_item.count('a')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N , Q = map(int,input().split())
S = list(input())
l = []
for i in range(Q):
	l.append(list(map(int,input().split())))
sum_AC = [0] * N
j = 0
count_AC = 0
while j < N:
	if S[j] == "A" and j != N-1:
		if S[j + 1] == "C":
			sum_AC[j] = count_AC
			count_AC += 1
			sum_AC[j+1] = count_AC
			j += 2
		else:
			sum_AC[j] = count_AC
			sum_AC[j+1] = count_AC
			j += 2
	else:
		sum_AC[j] = count_AC
		j += 1

		

for i in range(Q):
	start = l[i][0] - 1
	end = l[i][1] - 1
	print(sum_AC[end] - sum_AC[start])

Submission status: Wrong Answer

Solution code:
N , Q = map(int,input().split())
S = list(input())
l = []
for i in range(Q):
	l.append(list(map(int,input().split())))
sum_AC = [0] * N
j = 0
count_AC = 0
while j < N:
	if S[j] == "A" and j != N-1:
		if S[j + 1] == "C":
			sum_AC[j] = count_AC
			count_AC += 1
			sum_AC[j+1] = count_AC
			j += 2
		else:
			sum_AC[j] = count_AC
			sum_AC[j+1] = count_AC
			j += 2
	else:
		sum_AC[j] = count_AC
		j += 1

		
print(sum_AC)
for i in range(Q):
	start = l[i][0] - 1
	end = l[i][1] - 1
	print(sum_AC[end] - sum_AC[start])

Submission status: Wrong Answer

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

cnt = 0
for n in range(1, N):
    if S[n-1] + S[n] == "AC":
        cnt += 1
    SD[n] = cnt

print(SD)

for q in range(1, Q+1):
    l, r = map(int, input().split())
    print(SD.get(r-1, 0)-SD.get(l-1, 0))

Submission status: Wrong Answer

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

for n in range(N - 1):
    print(S[n])
    SD[n] = S[n]+S[n+1]

print(SD)
for q in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    print(SD[l-1:r-1].count("AC"))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(Q):
    count = 0
    S_temp = [ S[j] for j in range(rl[i][0]-1,rl[i][-1]) ]
    count = S_temp.count("AC")
    ans.append(count)
    
for i in range(Q):
    print(ans[i])

Submission status: Wrong Answer

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

for i in range(Q):
    count = 0
    S_temp = [ S[j] for j in range(rl[i][0]-1,rl[i][-1]-1) ]
    count = S_temp.count("A")
    ans.append(count)
    
for i in range(Q):
    print(ans[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(n)
print(q)

Submission status: Wrong Answer

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

rightmax = [0 for i in range(N+1)]
before = S[0]
nowAC = 0
for i, c in enumerate(S):
    if before == "A" and c == "C":
        nowAC += 1
    rightmax[i+1] = nowAC

for query in LR:
    l, r = map(int, query.split(" "))
    print(rightmax[r] - rightmax[l])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
        A_flag = False
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Submission status: Wrong Answer

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
            A_flag = False
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Submission status: Wrong Answer

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

S_count = []
count = 0
A_flag = False

for i in range(len(S)):
    if A_flag == True:
        if S[i] == "C" :
            count += 1
    else:
        if S[i] == "A" :
            A_flag = True
        else:
            A_flag = False
    S_count.append(count)

for i in range(Q):
    print(S_count[R[i] - 1] - S_count[L[i] - 1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))

Submission status: Wrong Answer

Solution code:
N, Q = map(int, raw_input().split())
string = raw_input()
a = []
for i in range(Q):
    a.append(map(int, raw_input().split()))
for temp in a:
    str_sub = string[temp[0]-1:temp[1]]
    print(str_sub)
    result = 0
    for i in range(len(str_sub)-1):
        if str_sub[i:i+2] == 'AC':
            result += 1
    print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(S)-1):
    if S[i] == 'A' and S[i+1] == 'C':
        S[i], S[i+1] = 2, -1
    else:
        if type(S[i]) != int:
            S[i] = 0

if type(S[-1]) == str:
    S[-1] = 0

print(S)

list_lr = [map(int, input().rstrip().split()) for i in range(Q)]

for i in list_lr:
    l, r = i
    s = S[l-1:r]
    print(s)
    if s[0] == -1 and s[-1] == 2:
        ans = sum(s)-1
    elif s[0] == -1 and (s[-1] == -1 or s[-1] == 0):
        ans = sum(s)+1
    elif s[-1] == 2 and (s[0] == 2 or s[1] == 0):
        ans = sum(s)-2
    else:
        ans = sum(s)

    print(int(ans))

Submission status: Wrong Answer

Solution code:
import re

pat = r'AC'
N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for i in range(Q)]
res = [len(re.findall(pat,S[l[0]:l[1]])) for l in lr]
for r in res:
    print(r)

Submission status: Wrong Answer

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

import array


def solv(n, q, s, lr):
    counts = array.array('i', [0] * len(s))
    count = 0
    mode = 0
    for i, c in enumerate(s):
        if c == 'A':
            mode = 1
        elif mode == 1 and c == 'C':
            count += 1
            mode = 0
        counts[i] = count

    ans = []
    for (ll, rr) in lr:
        ans.append(counts[rr-1] - counts[ll-1])
    return ans


if __name__ == '__main__':

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

    ans = solv(n, q, s, lr)

    for ans_i in ans:
        print(ans_i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    elif flag == 1 and S[i] == 'C':
        memo+=1
    elif S[i] in ['T','G','C']:
        flag = 0
    atgc_list.append(memo)
        

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

Submission status: Wrong Answer

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

atgc_list= []

flag = 0
memo =0

for i in range (len(S)):
    if S[i]=='A':
        flag = 1
    if flag == 1 and S[i] == 'C':
        memo+=1
    if S[i] in ['T','G']:
        flag = 0
    atgc_list.append(memo)
        

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

Submission status: Wrong Answer

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

acn=[0 for i in range(N)]
count=0
for i in range(1,N):
  if S[i-1]+S[i]=="AC":
    count+=1
  acn[i]=count
for i in range(Q):
  l=lr[i][0]
  r=lr[i][1]
  print(l,r)
  print(acn[r-1]-acn[l-1])

Submission status: Wrong Answer

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

result = 0
for i in range(q):
	num = counter[a[i][1]] - counter[a[i][0]]
	result += num
	print(num)

Submission status: Wrong Answer

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

result = 0
for i in range(q):
	num = counter[a[i][1]] - counter[a[i][0]]
	if counter[a[i][1]] - counter[a[i][1] - 1] != 0:
		num -= 1
	if a[i][0] != 0:
		if counter[a[i][0]] - counter[a[i][0] - 1] != 0:
			num += 1
	else:
		num += 1
	result += num
	print(num)

Submission status: Wrong Answer

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

S = input()
list1 = [0] * (N + 1)

for i in range(N):
        list1[i + 1] = list1[i] + (1 if S[i:i+2] == 'AC' else 0)
        print(list1)
for i in range(Q):
    l,r = map(int,input().split())
    print(list1[r-1]-list1[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)
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()
appmap = [0] * (n + 1)
for i in range(n):
    appmap[i + 1] = appmap[i] + (1 if s[i: i + 2] == "AC" else 0)
print(appmap)
for i in range(q):
    l, r = map(int, input().split())
    print(appmap[r - 1] - appmap[l - 1])

Submission status: Wrong Answer

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

list1 = []

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

for i in range(Q):
    print(S[list1[i][0]:list1[i][1]].count('AC'))

Submission status: Wrong Answer

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

def main():
    N, Q = map(int, input().strip().split())
    S = input()
    flg = False
    cnt = 0
    d = {}
    for i, c in enumerate(S):
        if c == 'A':
            flg = True
        elif c == 'C' and flg:
            # AC
            cnt += 1
            flg = False
        d[i] = cnt
    l = []
    r = []
    for _ in range(Q):
        ln, rn = map(int, input().strip().split())
        l.append(ln)
        r.append(rn)
    for ln, rn in zip(l, r):
        print(d[rn-1] - d[ln-1])



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

loc = [0 for i in range(N+1)]
for i in range(N) :
    if S[i:i+2] == "AC" :
        loc[i+1] = loc[i]+1
    else :
        loc[i+1] = loc[i]
for l,r in L :
    l -= 1
    r -= 1
    ans = loc[r] - loc[l]
    print(ans)
print(loc)

Submission status: Wrong Answer

Solution code:

x = input().split()
n = int(x[0]) # n == 比較文字列の長さ
q = int(x[1]) # q == 検討する回数
s = input()

def ind_Multi(a,b): #a,b == 検索範囲   
    global n
    global s 
    index_L = []
    for i in range(a,b):
        if s[i] == "A":
            index_L.append(i)
    return index_L

            
        
t = [0] * n
if s[0] == "A":
    t[0] = 1
    
for i in range(0,n-1):
    if s[i:i+2] == "AC":
        
        if (i == 0) :
            t[i] =  + 1
        else:
            t[i] = t[i-1] + 1
    else :
        if i == 0:
            t[i] = 0
        else:
            t[i] = t[i-1]



def sc():
    global t
    global s
    global n
    global q
    global idbox
    maxx = 0
    count = 0
    com = [int(s)-1 for s in input().split()]
    print(com)
    idbox = ind_Multi(com[0],com[1])
    print(t[com[1]-1] - t[com[0]-1])
        
    

    

for i in range(q):
    
    sc()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
n = int(input().split()[1])
s = input()
for i in range(n):
  l, r = map(int, input().split())
  ls = [len(i) for i in re.findall('AC', s[l-1: r])] + [0]
  print(max(ls))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

s=[0]

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

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

Submission status: Wrong Answer

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

for i in range(Q):
  l, r = map(int, input().split())
  cnt = 0
  for j in range(len(AC)):
    if AC[j] < l:
      continue
    if AC[j] > r:
      break
    cnt += 1
  print(cnt)

Submission status: Wrong Answer

Solution code:
ACGT = ['A', 'C', 'G', 'T']
try:
    N, Q = input().split()
except:
    print('2つのパラメータを入力してください')
    exit(0)
try:
    S = input()
    if len(S) != int(N):
        raise
    # 文字列がACGTのみであること
except:
    print('Nと文字数が一致していません')

inputArray = []
for i in range(int(Q)):
    l = input().split()
    inputArray.append(l)

for j in inputArray:
    # lからrまでの区間を抽出
    _string = S[ int(j[0]):int(j[1])+1 ]
    # 抽出した文字列の中にACがいくつ含まれるかx
    print(_string.count('AC'))

Submission status: Wrong Answer

Solution code:
_, num_query = list(map(int,input().split()))
string = input()
import re
pa = re.compile(r"[AC]")
for _ in range(num_query):
  left, right = list(map(int,input().split()))
  sub_string = string[left-1:right]
  print(len(pa.findall(sub_string)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(n + 1):
    a.append(s[:i].count('AC'))
print(a)
for i in range(q):
    x, y = map(int, input().split())
    print(a[y]-a[x])

Submission status: Wrong Answer

Solution code:
n, q = map(int, input().split())
s = str(input())
a = []
b = []
for i in range(q):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

ss = []
ll = []
for i in range(q):
    c = s[a[i]:b[i]]
    d = c.count('AC')
    print(d)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()

    ans = 0
    for i in range(len(s)):
        cur = 0
        for j in range(i,len(s)):
            if s[j] in {"A", "C", "G", "T"}:
                cur += 1

            else:
                break

            ans = max(cur, ans)


    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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


for i in range(q):
    print(N[Q[i][1]] - N[Q[i][0]])

Submission status: Wrong Answer

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

cum, now, bef = [], 0, False

for c in S:
    if bef and c == 'C':
        now += 1
    cum.append(now)
    if c == 'A':
        bef = True

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

Submission status: Wrong Answer

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

j = 0
b = [0]
while j < n - 1:
    if s[j] == 'A' and s[j+1] == 'C':
        if j > 0:
            b.append(b[j-1])
        b.append(b[j-1] + 1)
        j += 2
    else:
        b.append(b[j-1])
        j += 1
b.append(b[j-1])
for i in range(q):
    l, r = lr[i]
    print(b[r-1] - b[l-1])

Submission status: Wrong Answer

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

j = 0
b = [0]
while j < len(s) - 1:
    if s[j] == 'A' and s[j+1] == 'C':
        if j > 0:
            b.append(b[j-1])
        b.append(b[j-1] + 1)
        j += 2
    else:
        b.append(b[j-1])
        j += 1
b.append(b[j-1])
for i in range(q):
    l, r = lr[i]
    print(b[r-1] - b[l-1])

Submission status: Wrong Answer

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

i = 0
j = 0
b = [0]
while i < len(s) - 1:
    if s[i] == 'A' and s[i+1] == 'C':
        s = s[:i] + s[i+1:]
        s[i] = 'X'
        if i > 0:
            b.append(b[j-1])
        b.append(b[j-1] + 1)
        j += 2
    else:
        b.append(b[j-1])
        j += 1
    i += 1
b.append(b[j-1])
for i in range(q):
    l, r = lr[i]
    print(b[r-1] - b[l-1])

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
S = input()
tb = [0 for i in range(n)]
for i in range(n):
    if i==0 or S[i]!='C':
        tb[i] = tb[i-1]
        continue
    if S[i-1]=='A':
        tb[i] = tb[i-1]+1
for i in range(q):
    l,r = map(int,input().split())
    print(tb[r-1]-tb[l-1])

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
S = input()
tb = [0 for i in range(n)]
for i in range(n):
    if i==0 or S[i]!='C':
        tb[i] = tb[i-1]
        continue
    print(S[i])
    if S[i-1]=='A':
        tb[i] = tb[i-1]+1
for i in range(q):
    l,r = map(int,input().split())
    print(tb[r-1]-tb[l-1])

Submission status: Wrong Answer

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

for i in range(q):
    string = s[nums[i][0]-1:nums[i][1]]
    count = 0
    print(string)
    for j in range(len(string)-1):
        if string[j] == 'A':
            if string[j+1] == 'C':
                count += 1
    print(count)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

memo = []

def main():
    N,Q = map(int,input().split())
    S = input()
    for i in range(N-1):
        if S[i:i+2] == "AC":
            memo.append(i)
    print(memo)
    for i in range(Q):
        li,ri = map(int,input().split())
        count = len(memo)
        # 両方の範囲に入る最初と最後
        start = -1
        end = -1

        for i in range(len(memo)):
            if ac_check(i,li,ri):
                start = i
                break
        if start < 0:
            count = 0
        else:
            for i in reversed(range(len(memo))):
                if ac_check(i,li,ri):
                    end = i
                    break
            # print(start,end)
            count = count - (start) - (len(memo)-end) + 1

        print(count)

def ac_check(i,li,ri):
    if memo[i] >= li-1 and memo[i]+1 <= ri-1:
        return True
    return False

# def ac_check(sub_s):
#     count = 0
#     for i in range(len(sub_s)-1):
#         if sub_s[i:i+2] == "AC":
#             count += 1
#     return count


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,q = map(int, input().split())
s = input()
lr = [list(map(int, input().split())) for _ in range(q)]

acc = []
for i in range(n):
    if i==0:
        acc.append(0)
    else:
        if s[i-2:i]=="AC":
            acc.append(acc[-1]+1)
        else:
            acc.append(acc[-1])
acc.append(acc[-1])

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

Submission status: Wrong Answer

Solution code:

N, Q = map(int,input().split())
S = input()
L = []
ans = 0

for i in range(Q):
    ans = 0
    L.append(list(map(int,input().split())))
    for j in range(L[i][0],L[i][1]-1):
        if S[j] == "A":
            if S[j+1] == "C":
                ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=list(input())
print(S)
k=0
for i in range(Q):
  a,b=map(int,input().split())
  for j in range(a,b):
    if S[j-1]=="A"and S[j]=="C":
      k+=1
  print(k)
  k=0

Submission status: Wrong Answer

Solution code:
import sys

N,Q = map(int,input().split())
if 2 <= N <= 10^5 and 1 <= Q <= 10^5:
    S = input()
    if N == len(S):
        LR = [input().split() for _ in range(Q)]
        for lr in LR:
            l = int(lr[0])
            r = int(lr[1])
            if 1 <= int(l) <= N and 1 <= int(r) <= N:
                print(S[l-1:r].count('AC'))
            else:
                sys.exit()
    else:
        sys.exit()
else:
    sys.exit()

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
if 2 <= N <= 10^5 and 1 <= Q <= 10^5:
    S = input()
    if N == len(S):
        LR = [input().split() for _ in range(Q)]
        for lr in LR:
            l = int(lr[0])
            r = int(lr[1])
            if 1 <= int(l) <= N and 1 <= int(r) <= N:
                print(S[l-1:r].count('AC'))

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
if 2 <= N <= 10^5 and 1 <= Q <= 10^5:
    S = input()
    if N == len(S):
        LR = [input().split() for _ in range(Q)]
        for lr in LR:
            l = int(lr[0])
            r = int(lr[1])
            print(S[l-1:r].count('AC'))

Submission status: Wrong Answer

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

for i in range(1,n):
    a[i] = a[i-1]
    if (S[i-1]=='A')and(S[i]=='C'):
        a[i] += 1 
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, Q = map(int, input().split())
S = input()
LR = [[int(i)-1 for i in input().split()] for i in range(Q)]

flag = False
pre = []
count = 0
for i,s in enumerate(S):
  if s == 'A':
    flag = True
  elif s == 'C' and flag:
    count += 1
    flag = False
  else:
    pass
  pre.append(count)

for a in LR:
  print(pre[a[1]] - pre[a[0]])

Submission status: Wrong Answer

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

# print("N:", N)
# print("S:", S)
# print("my_list:", my_list)

my_str_list = [0]
count = 0
for i in range(1, len(S)):
    if (S[i] == 'C' and S[i-1] == 'A'):
        count = count + 1
    my_str_list.append(count)
#print(my_str_list)

for i in range(Q):
    (l, r ) = my_list[i]
#    print(l, r)
    ret = my_str_list[r-1] - my_str_list[l-1]
    if (S[l-2] == 'A'):
        ret = ret - 1
        ret = 0 if ret < 0 else ret
    print(ret)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(input())
l1=[0]
p=0
for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    p+=1
    l1.append(p)
  else:
    l1.append(p)
for t in range(m):
  i,j=map(int,input().split())
  print(l1[i-1]-l1[j-1])

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=list(input())
l1=[0]
i=0
for i in range(n-1):
  if l[i]=="A" and l[i+1]=="C":
    i+=1
    l1.append(i)
  else:
    l1.append(i)
for t in range(m):
  i,j=map(int,input().split())
  print(l1[j-1]-l1[i-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

for i in range(q):
    ans=sum(V[X[i][0]-1:X[i][1]])
    if V[X[i][1]-1]==1:
        ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
input_num=list(input())
input_str=list(input())
anslen=[]
for i in range(int(input_num[2])):
  divpoint=list(input())
  k=''.join(input_str[int(divpoint[0])-1:int(divpoint[2])])
  anslen.append(k.count("AC"))
for i in range(int(input_num[2])):
  print(anslen[i])

Submission status: Wrong Answer

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

cs = [0] * N
s = 0
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        s += 1
    cs[i+1] = s 
cs[N-1] = cs[N-2]

for l, r in lrs:
    print(cs[r-1] - cs[l-1])