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:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

def bsearch(arr, num):
    r = len(arr) - 1
    l = 0
    while r - l > 1:
        c = (r + l) // 2
        if arr[c] > num:
            r = c
        elif arr[c] < num:
            l = c
        else:
            l = c
            r = c
            break
    return [l, r]

n, q = MAP()
s = STR()
index = []
for i in range(len(s) - 1):
    if s[i] + s[i + 1] == 'AC':
        index.append(i)
print(index)
if len(index) > 1:
    for _ in range(q):
        l, r = MAP()
        ll = bsearch(index, l - 1)
        rr = bsearch(index, r - 2)
        lll = ll[0] if index[ll[0]] >= l - 1 else ll[1]
        rrr = rr[1] if index[rr[1]] <= r - 2 else rr[0]
        print(rrr - lll + 1)
elif len(index) == 1:
    t = index[0]
    for _ in range(q):
        l, r = MAP()
        if l - 1 <= t <= r - 2:
            print(1)
        else:
            print(0)
else:
    for _ in range(q):
        print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(1, N):
    T[i+1] = 1 if S[i-1:i+1]=='AC' else 0
for _ in range(Q):
    l, r = map(int, input().split())
    print(T[:r+1].count(1) - T[:l].count(1))

Submission status: Wrong Answer

Solution code:

import bisect


def read_input():
    n, q = map(int, input().split())
    s = list(input().strip())
    queries = []
    for _ in range(q):
        st, ed = map(int, input().split())
        queries.append((st - 1, ed - 1))

    return n, s, queries


def submit():
    n, s, queries = read_input()

    # AC pointを列挙する
    ac_st = []
    for i in range(n - 1):
        if s[i] == "A" and s[i + 1] == "C":
            ac_st.append(i)

    print(ac_st)

    for ql, qr in queries:
        print(bisect.bisect_right(ac_st, qr - 1) -\
              bisect.bisect_left(ac_st, ql))


if __name__ == "__main__":
    submit()

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
print(l)
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[max(h-2,0)])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
print(l)
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[max(0,h-2)])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
print(l)
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-2])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
l=[0 for i in range(n)]
for i,v in enumerate(list(input().replace("AC","X!"))):
    l[i]=l[i-1]+(v=="!")
print(l)
for c in range(q):
    h,m=map(int,input().split())
    print(l[m-1]-l[h-1])

Submission status: Wrong Answer

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

def inp(l: list) -> list:
    return [int(l[0]) - 1, int(l[1]) - 1]

for i in range(q):
    lr[i] = tuple(inp(input().split()))

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

print(count)

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

Submission status: Wrong Answer

Solution code:
#ABC122C 累積和
from itertools import accumulate
A = []
N, Q = map(int, input().split())
B = [0]*N
S = list(input())
ans = []
for i in range(1, N):
    if S[i-1]=='A' and S[i]=='C':
        B[i] = 1
A = list(accumulate(B))
print(A)
for j in range(Q):
    l, r = map(int, input().split())
    ans.append(A[r-1]-A[l-1])
print('\n'.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
def main():
  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])
if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
for i in range(Q):
  l,r=map(int,input().split())
  a=l
  b=r+1
  c=S.count('AC',a,b)
  print(c)

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
def main():
  for i in range(Q):
    l,r=map(int,input().split())
    a=l
    b=r+1
    c=S.count('AC',a,b)
    print(c)
main()

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
L=[]
R=[]
for j in range(Q):
  l,r=map(int,input().split())
  L.append(l)
  R.append(r)
def main():
  for i in range(Q):
    a=L[i]
    b=R[i]+1
    c=S.count('AC',a,b)
    print(c)
main()

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
questions = [[i for i in map(int,input().split())] for j in range(Q)]
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 q in questions:
  print(t[q[1]-1] - t[q[0]-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = [i for i in input()]
questions = [[i-1 for i in map(int,input().split())] for j in range(Q)]
sums = [0]*N

for i in range(len(S)-1):
  if S[i]=='A' and S[i+1]=='C':
    S[i]='a'
    sums[i+1] = sums[i]+1
  else:
    sums[i+1] = sums[i]
    
print(sums)
    
for q in questions:
  part_S = S[q[0]:q[1]+1]
  ans = sums[q[1]]-sums[q[0]]
  print(ans)

Submission status: Wrong Answer

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

    dp = count_ac(S)
    query = []
    for _ in range(Q):
        l, r = [int(v) - 1 for v in input().split()]
        query.append((l, r))

    for l, r in query:
        print(dp[r] - dp[l])


def count_ac(s):
    dp = [0] * len(s)
    count = 0
    state = 0
    for i, c in enumerate(list(s)):
        if state == 0:
            if c == 'A':
                state = 1
        elif state == 1:
            if c == 'C':
                count += 1
            state = 0
        dp[i] = count
    return dp


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations
    #from itertools import accumulate, product, permutations
    from math import floor, ceil

    #mod = 1000000007

    n,q = map(int, input().split())
    s = input()
    for _ in range(q):
        res = 0
        l, r = map(int, input().split())
        moji = s[l-1:r]
        print(len(moji.split('AC')))
        # for i in range(len(moji)-1):
        #     if moji[i]=='A' and moji[i+1]=='C':
        #         res += 1
        # print(res)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from operator import itemgetter 
n,q=map(int,input().split())
s=input()
ac=[0]
buf=0
data=[]
for i in range(1,n):
    if s[i-1:i+1]=="AC":
        buf+=1
    ac.append(buf)
for i in range(q):
    l,r=map(int,input().split())
    data.append([l,r,i])
data.sort()
buf=0
i=0
while i<q:
    data_i=data[i][0]-1
    ac_i=ac[0]
    if buf!=data_i:
        ac_i=-1*ac[data_i]
        buf=data_i
    data[i].append(ac_i)
    i+=1
data.sort(key=itemgetter(1))
buf=0
i=0
while i<q:
    data_i=data[i][1]-1
    ac_i=ac[0]
    if buf!=data_i:
        ac_i=ac[data_i]
        buf=data_i
    data[i][3]+=ac_i
    i+=1
data.sort(key=itemgetter(2))
i=0
for i in range(q):
    print(data[i][3])

Submission status: Wrong Answer

Solution code:
from operator import itemgetter 
n,q=map(int,input().split())
s=input()
ac=[0]
buf=0
data=[]
for i in range(1,n):
    if s[i-1:i+1]=="AC":
        buf+=1
    ac.append(buf)
print(ac)
for i in range(q):
    l,r=map(int,input().split())
    data.append([l,r,i])
print(data)
data.sort()
buf=0
i=0
while i<q:
    data_i=data[i][0]-1
    ac_i=ac[0]
    if buf!=data_i:
        ac_i=-1*ac[data_i]
        buf=data_i
    data[i].append(ac_i)
    i+=1
print(data)
data.sort(key=itemgetter(1))
print(data)
buf=0
i=0
while i<q:
    data_i=data[i][1]-1
    ac_i=ac[0]
    if buf!=data_i:
        ac_i=ac[data_i]
        buf=data_i
    data[i][3]+=ac_i
    i+=1
data.sort(key=itemgetter(2))
i=0
for i in range(q):
    print(data[i][3])

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, q = na()
s = ns()
ac = [0]
now = 0
f = False
for si in s:
    if si == "C" and f:
        now += 1
        f = False
    elif si == "A":
        f = True
    else:
        f = False
    ac.append(now)
for _ in range(q):
    l, r = na()
    print(ac[r] - ac[l-1])

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n, q = na()
s = ns()
ac = []
now = 0
f = False
for si in s:
    if si == "C" and f:
        now += 1
        f = False
    elif si == "A":
        f = True
    else:
        f = False
    ac.append(now)
ac.append(now)
for _ in range(q):
    l, r = na()
    print(ac[r] - ac[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input().strip()
b = None
nm = 0
dp = [0]
for c in S:
#    if b == None:
#        b = c
#        continue
    if b == 'A' and c == 'C':
        nm += 1
    dp.append(nm)
    b = c
print(dp)
for _ in range(Q):
    l, r = map(int, input().split())
    print(dp[r]-dp[l])

Submission status: Wrong Answer

Solution code:
n,q = map(int,input().split())
s = input()
ac = []
ans = []
for i in range(len(s)-1):
    if s[i]=="A":
        if s[i+1]=="C":
            ac.append(i+1)

for i in range(q):
    l,r = map(int,input().split())
    ct = [i for i in ac if i >= l and i+1 <= r] 
    an = len(ct)
    ans.append(an)
#ここから出力
print(ans)

Submission status: Wrong Answer

Solution code:
N, Q = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()] for _ in range(Q)]
ary = [0]
c = 0
f = bool(S[0] == "A")
for i in range(1, N):
    if S[i] == 'C' and f:
        c += 1
        f = False
    else:
        f = bool(S[0] == "A")
    ary.append(c)
for l, r in lr:
    print(ary[r-1]-ary[max(0, l-1)])

Submission status: Wrong Answer

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

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

ans = []
for _ in range(Q):
    l,r = [int(zz)-1 for zz in input().split()]
    ans.append(li[r]-li[l])

[print(i) for i in ans]

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:
a,b = map(int,input().split())
s = input()
L = [0]*a
li = [0]*(a+1)
for i in range(a-1):
    if s[i] == "A" and s[i+1] == "C":
        L[i] = 1
        L[i+1] = 0
li[0] = L[0]
for i in range(1,a):
    li[i] = li[i-1] + L[i]
li = [0]+li
for i in range(b):
    c,d = map(int,input().split())
    if d-c == 1:
        if s[c:d] == "AC":
            print(1)
        else:
            print(0)
    else:
        print(li[d-1]-li[c-1])

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

n, q = map(int, input().split())
s = list(input())
#print(s)
z = []
for i in range(n-1):
    if s[i] + s[i+1] == 'AC':
        z.append(1)
    else:
        z.append(0)
print(z)

z = [0] + list(accumulate(z))
print(z)

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

Submission status: Wrong Answer

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

def check(S): #1 moji
    if S == "AC":
        return True
    else:
        return False

ans = [0]*Q

for i in range(Q):
    for j in range(L[i][0]-1,L[i][1]-1):
        if check(S[j:j+2]):
            ans[i]+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, q = map(int, input().split())
s = input()
w = np.zeros(n, dtype=int)

a = 0
for i in range(n):
    if s[i] == "A":
        if a == 0:
            a += 1
    elif s[i] == "C":
        if a:
            w[i-1] = 1
            a -= 1
    else:
        pass

ans = np.append(np.zeros(1, dtype=int), np.cumsum(w))
for _ in range(q):
    l, r = map(int, input().split())
    print(ans[r-1] - ans[l-1])

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N,Q=map(int, input().split())
S=input()
L=[None]*(N)
t=0
for i in range(N-1):
    L[i]=t
    if S[i]=="A" and S[i+1]=="C":
        t+=1
L[-1]=t
for i in range(Q):
    l,r=map(lambda x:int(x)-1,input().split())
    print(L[r-1]-L[l-1])

Submission status: Wrong Answer

Solution code:
N, Q = [int(i) for i in input().split()]
S = input()
ary = [0]*(N+1)
af = False
ans = []
for i, s in enumerate(S):
    ary[i+1] = ary[i]
    if s == "A":
        af = True
    elif s == "C" and af:
        ary[i+1] += 1
    else:
        af = False
for _ in range(Q):
    l, r = [int(i) for i in input().split()]
    ans.append(ary[r]-ary[l])
for a in ans:
    print(a)

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=[0,0]
c=0
for i in range(1,n):
	if s[i-1]=='A' and s[i]=='C':
		c += 1
	L.append(c)
print(L)
for l,r in lr:
	print(L[r]-L[l-1])

Submission status: Wrong Answer

Solution code:
N,Q = map(int,input().split())
S = input()
X = []
x = 0
check = 0
for i in S:
    if check == 1 and i == 'C':
        x += 1
        check = 0
    if i == 'A':
        check = 1
    else:
        chekc = 0
    X.append(x)
#print(X)
A = []
for _ in range(Q):
    l,r = map(int,input().split())
    ans = X[r-1] - X[l-1]
    A.append(ans)
for i in A:
    print(i)

Submission status: Wrong Answer

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

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=[0,0]
c=0
for i in range(1,n):
	if s[i-1]=='A' and s[i]=='C':
		c += 1
	L.append(c)
print(L)
for l,r in lr:
	print(L[r]-L[l])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
S=input()
s_cnt=[]
for i in range(N):
    s_cnt.append(S[:i+2].count("AC"))
for i in range(Q):
    l,r=map(int,input().split())
    print(s_cnt[r-1] - s_cnt[l-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(q):
  l, r = map(int, input().split())
  tmp = s[l-1:r]
  print(tmp)
  if len(tmp) > 0:
    count = 0
    for j in range(0, len(tmp)-1):
      if s[i] == "A" and s[i+1] == "C":
        count+=1
    print(count//2)
  else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N, Q = map(int, input().split())
S = input()
arr = []
for i in range(N-1):
  if S[i:i+2] == "AC":
    arr.append(i)
print(arr)
for i in range(Q):
  l, r = map(int, input().split())
  print(bisect.bisect_right(arr, r-2) - bisect.bisect_left(arr, l-1))

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
cnt=[0]*n
icnt=0
for i in range(n-1):
#    print(s[i:i+2])
    if s[i:i+2]=="AT":
      icnt=icnt+1
      cnt[i+1]=cnt[i]+1
    else:
      cnt[i+1]=cnt[i]
#print(cnt,s)
for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
#    print(sum(cnt[li-1:ri-1]))
    print(cnt[ri-1]-cnt[li-1])

Submission status: Wrong Answer

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

for i in range(q):
    li,ri=map(int,input().split())
#    print(s[li-1:ri].count("AC"))
    print(sum(cnt[li-1:ri-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)]

ss=[0]*(n+1)

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

for i in range(q):
    if lr[i][1] - lr[i][0] ==1:
        print(0)
    else:
        print(ss[lr[i][1]] - ss[lr[i][0]])

Submission status: Wrong Answer

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

t = [0] * len(S)

for index, s in enumerate(S):
  if index+1 > len(S)-1:
    break

  if s == 'A' and S[index+1] == 'C':
    t[index+1] = t[index] + 1
    
  else:
    t[index+1] = t[index]
    
print(t)

for i in li:
  print(t[i[1]-1] - t[i[0] - 1])

Submission status: Wrong Answer

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

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
print(ln)
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S=input()
count=0
for j in range(Q):
    l, r = map(int, input().split())
    s=S[l-1:r]
    count+=s.count("AC")
print(count)

Submission status: Wrong Answer

Solution code:
import bisect

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

AC_list = list()

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

#print(AC_list)  
  
for i in range(Q):
  l,r = map(int, input().split())
  index_left = bisect.bisect_left(AC_list, l)
  index_right = bisect.bisect_left(AC_list, r-1)
  #print(index_left,index_right)
  if index_right - index_left == 0:
    print(0)
  else:
    print(1+index_right - index_left)

Submission status: Wrong Answer

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

  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from bisect import bisect

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

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

for i in range(q):
	print(bisect(c,r[i])-bisect(a,l[i])+1)

Submission status: Wrong Answer

Solution code:
def calculate(n,q,S):
    indexes = [0 for i in range(n)]

    arr = list(S)

    for i in range(len(arr)):
        if i == 0:
            indexes[i] = 0
            continue
        if arr[i] == 'C':
            if arr[i-1] == 'A':
                indexes[i] = indexes[i-1] + 1
        else:
            indexes[i] = indexes[i-1]
    return indexes

def conclution(res,Q):
    for qrr in Q:
        s2 = res[qrr[1]-1]
        s1 = res[qrr[0]-1]
        print(s2-s1)


input1 = input().split(" ")

n = int(input1[0])
q = int(input1[1])
S = input()

res = calculate(n,q,S)

qrr = []

for i in range(q):
    qrr.append([int(s) for s in input().split()])

conclution(res, qrr)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for _ in range(Q):
    l, r = map(int, input().split())
    if r - l == 1:
        if S[l:r+1] == 'AC':
            print(1)
        else:
            print(0)
    else:
        print(acm_cntAC[r] - acm_cntAC[l-1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

csm = [0]
cnt = 0

for i in range(n - 1):
	if s[i:i+2] == 'AC':
		cnt += 1
	csm.append(cnt)

print(csm)
	
for j in range(q):
	print(csm[ls[j][1] - 1] - csm[ls[j][0] - 1])

Submission status: Wrong Answer

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

flag = [0] * (n - 1)

for i in range(n - 1):
	if s[i:i+2] == 'AC':
		flag[i] = 1
	
for j in range(q):
	print(sum(flag[ls[j][0] - 1:ls[j][1] - 2]))

Submission status: Wrong Answer

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

def main():
    N, Q = map(int, input().split())
    S = list(input().rstrip())

    dec_a = [0] * (N)
    for x in range(1, N):
        if S[x] == 'C' and S[x-1] == 'A':
            S[x-1] = 'a'
        dec_a[x] = S[:x+1].count('a')


    L = [0] * Q
    R = [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())

    print(dec_a)
    for j in range(Q):
        print(dec_a[R[j]-1] - dec_a[L[j]-1])

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
acc = []
for i in range(1, len(S)+2):
    acc.append(S[0:i].count("AC"))

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

Submission status: Wrong Answer

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

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


print(data)

for l,r in LR:
    print(data[r-1]-data[l-1])

Submission status: Wrong Answer

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

for _ in range(Q):
  l,r = map(int,input().split())
  bottom = -1
  top = -1
  if len(index) != 0:
    for i in range(len(index)):
      if l <= index[i]+1:
        bottom = i
        break
    for j in range(len(index)):
      if index[-(i+1)] < r-1:
        top = len(index) -1 -j
        break
  Answer = 0
  if top >= bottom:
    Answer = top - bottom + 1
  print(Answer)