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 itertools

nq = input().split()
n = int(nq[0])
q = int(nq[1])

text = input()

questions = [input() for i in range(q)]

print(questions)
print(text)

flag = []

for i in range(n-1):
    tmp_S = text[i:i+2]
    if tmp_S == 'AC':
        flag.append(1)
    else:
        flag.append(0)

flag = [0] + flag
print(flag)

accm_flag = list(itertools.accumulate(flag))
print(accm_flag)

for question in questions:
  question = question.split()
  print(accm_flag[int(question[1])-1] - accm_flag[int(question[0])-1])

Submission status: Wrong Answer

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

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

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

Submission status: Wrong Answer

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

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

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

Submission status: Wrong Answer

Solution code:
n, q=map(int,input().split())
str=input() #ただの文字列
q_list=[input().split() for _ in range(q)]  #問題の数が入ったリスト
pattern='AC'

#strのi番目までににACが何個あるか
count_ac=[0 for i in range(len(str))]
count=0
for i in range(len(count_ac)-1):
    if str[i]=='A' and str[i+1]=='C':
        count+=1
        count_ac[i]=count
    else:
        count_ac[i]=count
count_ac[len(str)-1]=count    
print(count_ac)
for a,b in q_list:
    A,B=int(a),int(b)
    if A>=2:
        print(count_ac[B-2]-count_ac[A-2])
    elif B>=2 and A<2:
        print(count_ac[B-2])
    else:
        print(0)

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 t[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()
A = [0, 0]
c = 0
for i in range(1,N):
    if S[i-1:i+1] == "AC":
        c += 1
    A.append(c)
print(A)
for _ in range(Q):
    l, r = map(int, input().split())
    print(A[r]-A[l])

Submission status: Wrong Answer

Solution code:
# C - GeT AC
# https://atcoder.jp/contests/abc122/tasks/abc122_c
import sys
n, q = list(map(int, sys.stdin.readline().split()))

s = input()

separators = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

# n = 8
# q = 3
# s = 'ACACTACG'
# separators = [[3, 7],[2, 3],[1, 8]]

cnt = []

for index in range(0, len(separators)):
    cnt.append(s[separators[index][0]:separators[index][1]].count('AC'))

for i in cnt:
    print(i)

Submission status: Wrong Answer

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

lr = []
for _ in range(Q):
    lr.append(list(map(int,input().split(' '))))

index_list = []
#index_list = [0] * N
start = 0
for i in range(N):
    if S[i-1] == 'A' and S[i] == 'C':
        start += 1
        #index_list[i] = index_list[i-1] + 1
    #else:
    index_list.append(start)
        #index_list[i] = index_list[i-1]

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

Submission status: Wrong Answer

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

a = [0 for i in range(len(s)+1)]
for i in range(2,len(s)):
  if s[i-2] is 'A' and s[i-1] is'C':
    a[i] += 1
  a[i] += a[i-1]
for _ in range(q):
  li,ri = map(int,input().split())
  print(a[ri]-a[li])

Submission status: Wrong Answer

Solution code:
from math import ceil


def main(N, Q, S, lr_list):
    res = []
    for lr in lr_list:
        l, r = lr
        res.append(S[l-1:r].count("AC"))
    return res


if __name__ == "__main__":
    N, Q = list(map(int, input().split()))
    S = input()
    lr_list = []
    for _ in range(Q):
        lr_list.append(tuple(map(int, input().split())))
    print(main(N, Q, S, lr_list))

Submission status: Wrong Answer

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


def main():
    n, q = map(int, input().split())
    s = input()
    x = [0] * n
    if s[0:2] == 'AC':
        x[0] = 1
    for i in range(n - 1):
        if s[i+1:i+3] == 'AC':
            x[i+1] = x[i] + 1
        else:
            x[i+1] = x[i]

    print(x)
    result = []
    for _ in range(q):
        li, ri = map(int, input().split())
        li -= 1
        ri -= 1
        lsum = 0 if li == 0 else x[li-1]
        rsum = x[ri-1]
        result.append(rsum - lsum)

    for v in result:
        print(v)

if __name__ == '__main__':
    main()

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:
import sys  
from itertools import accumulate
input = sys.stdin.readline  

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

l = [None]*Q
r = [None]*Q
for i in range(Q):
    l[i], r[i] = list(map(int, input().split()))

s = list(S)
ac = [0] * N

for i in range(N-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            s[i] = "AC"
            ac[i] += 1

#ans = list(accumulate(ac))
#ans = [0] + ans


#for i in range(Q):
#    print(ans[r[i]-1]- ans[l[i]-1])
for i in range(Q):
    print(sum(ac[r[i]:l[i]]))

Submission status: Wrong Answer

Solution code:
import re
n,q=map(int,input().split())
s=input()
a=[0]*n
b=[0]*n
i=[p.span()[0]for p in re.finditer('(AC){1,1}',s)]
c=0
for m in range(n):
  if c>=len(i):
    if m<n-1:a[m+1]=a[m]
    b[m]=b[m-1]
    continue
  if m==i[c]:
    if m>0:
      if m<n-1:a[m+1]=a[m]+1
      b[m]=b[m-1]+1
    else:
      a[m]=0
      a[m+1]=1
      b[m]+=1
    c+=1
  else:
    a[m+1]=a[m]
    b[m]=b[m-1]
for _ in range(q):
  l,r=map(int,input().split())
  print(max(a[r-1]-(b[l-1]-1),0))

Submission status: Wrong Answer

Solution code:
import re
n,q=map(int,input().split())
s=input()
i=[p.span()[0] for p in re.finditer('(AC){1,1}',s)]
print(i)
for _ in range(q):
  v=0
  l,r=map(int,input().split())
  for c in i:
    v+= l-1<=c and c+1<=r-1
  print(v)

Submission status: Wrong Answer

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

Sum = [0]
for i in range(len(s)):
    if s[i-1]=="A" and s[i]=="C":
        Sum.append(Sum[i]+1)
    else:
        Sum.append(Sum[i])

print(Sum)
for i in range(q):
    print(Sum[r[i]]-Sum[l[i]])

Submission status: Wrong Answer

Solution code:
n, q = map(int,input().split())
S = list(input())
L = []
R = []
for i in range(q):
    l, r = [int(i) for i in input().split()]
    L.append(l)
    R.append(r)
for i in range(q):
    S_0 = ""
    for k in range(L[i], R[i]):
        S_0 += S[k]
    print(S_0.count("AC"))

Submission status: Wrong Answer

Solution code:
import re
n,q = map(int, input().split())
s = input()
for i in range(q):
    a = [int(s) for s in input().split()]
    print(re.findall("AC",s[a[0]-1:a[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)]
x=[0]
j=False
t=0
for i in range(n):
    if i==0:
        if s[i]=="A":
            j=True
    elif j==True:
        if s[i]=="C":
            t+=1
        j=False
    elif s[i]=="A":
        j=True
    x.append(t)
for l,r in lr:
    print(x[r]-x[l])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]
x=[0]
j=False
t=0
for i in range(n):
    if i==0:
        if s[i]=="A":
            j=True
    elif j==True:
        if s[i]=="C":
            t+=1
            j=False
        else:
            j=False
    else:
        if s[i]=="A":
            j=True
    x.append(t)
for l,r in lr:
    print(x[r]-x[l])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

aclist = []
for j in range(n - 1):
  if s[j] == "A" and s[j + 1] == "C":
    aclist.append(j)

anslist = []
for k in range(q):
  ans = 0
  for e in aclist:
    if inputlist[k][0] <= e and e < inputlist[k][1]:
      ans += 1
    if inputlist[k][1] <= e:
      break
  anslist.append(ans)
  
print(*anslist, sep = "\n")

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
s=list(input())
p=[]
li=[]
ri=[]
for i in range(Q):
  l,r=map(int,input().split())
  li.append(l)
  ri.append(r)
  pr=0
  for j in range(ri[i]-li[i]-1):
      if s[li[i]+j]=='A' and s[li[i]+j+1]=='C':
          pr +=1
      else:
          pass
  p.append(pr)
for i in range(Q):
  print(p[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = str(input())
LR = [list(map(int, input().split())) for i in range(Q)]
for i in range(Q):
    STR = S[LR[i][0]-1:LR[i][1]]
    if('AC' in STR):
        print(STR.count('AC'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S=input()

ACDP=[0]*N
Aflag=0
ACcount=0
for i in range(len(S)):
  if S[i]=='A':
    Aflag=1
  if S[i]=='C' and Aflag==1:
    ACcount+=1
  ACDP[i]=ACcount
#print(ACDP)

for _ in range(Q):
  start,end=map(int,input().split())
  print(ACDP[end-1]-ACDP[start-1])

Submission status: Wrong Answer

Solution code:
def hoge(tag, l):
    for i, t in enumerate(tag):
        if l <= t:
            return i
            break
    else:
        return len(tag) - 1


N, Q = map(int, input().split())
S = input()
tag = []
for i in range(N):
    if S[i] == 'C' and S[i - 1] == 'A':
        tag.append(i)
# print(tag)
for i in range(Q):
    l, r = map(int, input().split())
    L = hoge(tag, l)
    R = hoge(tag, r)
    ans = R - L
    if 0 < ans:
        ans += 1
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate

N,Q=map(int,input().split())
S=input()
count=[0]*(N)
for i in range(N-1):
    if S[i:i+2]=="AC":
        count[i]=1
sums=list(accumulate([0]+count))
print(S)
print(sums)
for i in range(Q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    print(sums[r]-sums[l])

Submission status: Wrong Answer

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

def gen_idx_list(S):
  result_list = []
  for i in range(len(S) - 1):
    if S[i] == "A" and S[i+1] == "C":
      result_list.append(i+1)
  return result_list

idx_list = gen_idx_list(S)
print(idx_list)

for _ in range(Q):
  l, r = list(map(int, input().split()))
  print(len([x for x in idx_list if l <= x and x < r]))

Submission status: Wrong Answer

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

p = []
i = 0
while i < len(s) - 1:
    if s[i:i+2] == 'AC':
        p.append(i)
        i += 2
    else:
        i += 1

m = [0 for _ in range(len(s) + 1)]

c = 0
for i in range(len(s)):
    if s[i:i+2] == 'AC':
        c += 1
    m[i + 1] = c

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    if c == 0:
        print(0)

    # print(m)
    # print(l, r)
    # print(m[1:][r - 1], m[l])
    print(m[1:][r - 1] - m[l])

    # print()

Submission status: Wrong Answer

Solution code:
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, q = read_line(int, int)
s, = read_line(str)

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

for i in range(q):
    l, r = read_line(int, int)
    l, r = l - 1, r - 1

    c = 0
    for pp in p:
        if l <= pp and pp + 1 < r:
            c += 1
    print(c)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [LIST() for _ in range(Q)]

accum = []
count = 0

for i in range(len(S)-1):
	accum.append(count)
	if S[i] == "A" and S[i+1] == "C":
		count += 1
accum.append(count)
print(accum)
for l, r in lr:
	print(accum[r-1]-accum[l-1])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, Q = MAP()
S = input()
lr = [LIST() for _ in range(Q)]

accum = []
count = 0

for i in range(len(S)-1):
	accum.append(count)
	if S[i] == "A" and S[i+1]:
		count += 1
accum.append(count)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#累積和による解法

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

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

Submission status: Wrong Answer

Solution code:
#累積和による解法

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

for i in range(N+1):
    S_part = S[:i]
    cnt = S_part.count("AC")
    cnt_list.append(cnt)
for j in range(Q):
    l,r = map(int, input().split())
    ans = cnt_list[r]-cnt_list[l-1]
    if cnt_list[l-1]==cnt_list[l-2]:
        ans -= 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N, Q = [int(i) for i in input().split()]
S = list(input())
term = [[int(i) for i in input().split()] for x in range(Q)]
times = 0
ACs = []
ans = []

for i in range(len(S) - 1):
    if (S[i] == 'A' and S[i + 1] == 'C'):
        times += 1
        ACs.append(i)
        
if times == 0:
    for i in range(Q):
        print(0)
        sys.exit()
else:
    times = 0

for i in range(len(term)):
    for j in range(len(ACs)):
        if term[i][0] <= ACs[j] + 1 < term[i][1]:
            times += 1
    ans.append(times)
    times = 0

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

Submission status: Wrong Answer

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

acc[N-1] = acc[N-2]
print(acc)
for i in range(Q):
    l,r = map(int,input().split(" "))
    if l > 1:
        ans = acc[r-1] - acc[l-2]
    else:
        ans = acc[r-1]
    if a[r-1] == 1:
        ans -= 1
    
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def isAC(i):
    return s[i:i + 2] == "AC"

cs = [0] * n
for i, v in enumerate(s[:-1]):
    if isAC(i):
        cs[i] = 1

cs.insert(0, 0)
for i in range(1, len(cs)):
    cs[i] += cs[i - 1]

for query in range(q):
    left, right = map(int, input().split())
    result = cs[right] - cs[left - 1]
    if right < n - 1 and isAC(right - 1):
        result -= 1
    print(result)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
s=input()
l=[0]
x,y=0,0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":x+=1
    l.append(x)
l.append(x)
for i in range(m):
    a,b=map(int,input().split())
    print(l[b]-l[a-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] = (1 if s[i:i + 2] == "AC" else 0) + t[i]
print(t)
for i in range(q):
    l, r = list(map(int, input().split()))
    print(t[r - 1] - t[l - 1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
hoge=input()
huga=[0]
for i in range(n-1):
  flag=0
  if(hoge[i]=="A" and hoge[i+1]=="C"):
    flag=1
  huga.append(huga[-1]+flag)
  
print(huga)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
length, loop_count = list(map(int, input().split()))
s = input()

count = 0

while loop_count > 0:
  start, end = list(map(int, input().split()))
  s_select = s[start-1:end]
  print(s_select)
  for i in range(0, len(s_select)-1):
    if s_select[i] == 'A' and s_select[i+1] == 'C':
      count += 1
  print(count)
  
  loop_count -= 1
  count = 0

Submission status: Wrong Answer

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


t = [0] * n
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        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-1] - t[l-1])

Submission status: Wrong Answer

Solution code:
n,q=map(int,input().split())
s=input()
ac=[0]*(n-1)
for i in range(n-1):
  ac[i]=(s[i]=="A" and s[i+1]=="C")
ans=""
for i in range(q):
  l,r=map(int,input().split())
  ans+=str(sum(ac[l-1:r]))+"\n"
print(ans,end="")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input()
rr = (list(map(int, input().split())) for _ in range(k))

from collections import Counter

dc = [0, 0]
c = 0
for i in range(1, len(s)):
  if s[i-1]+s[i] == 'AC':
    c += 1
  dc.append(c)
for a, b in rr:
  print(dc[b] - dc[a-1])

Submission status: Wrong Answer

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

for cnt in range(q):
  res =0
  l, r = list(map(int, input().split()))
  cs = s[l-1:r]
  print(cs)
  for tmp in range(len(cs)-1):
    if(cs[tmp] == 'A' and cs[tmp+1] =='C'):
      res += 1

  print(res)

Submission status: Wrong Answer

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

def gen_idx_list(S):
  result_list = []
  for i in range(len(S) - 1):
    if S[i] == "A" and S[i+1] == "C":
      result_list.append(i)
  return result_list

idx_list = gen_idx_list(S)
print(idx_list)

for _ in range(Q):
  l, r = list(map(int, input().split()))
  print(len([x for x in idx_list if l-1 <= x and x < r-1]))

Submission status: Wrong Answer

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

plc=[0]*N

for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    plc[i+1] = 1
  else:
    plc[i+1] = 0

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n,q =map(int,input().split())
l = list(input())
counter = 0

Start_end = []
for i in range(q):
    n_list = [int(x) for x in input().split()]
    Start_end.append(n_list)

for i in range(q):
    for j in range(Start_end[i][0],Start_end[i][1]):
        if(l[j-1] + l[j] == "AC"):
            counter += 1

    counter = 0

Submission status: Wrong Answer

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

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

for i in range(q):
    l, r = (lists[i][0] - 1), (lists[i][1] - 1)
    for j in AC_index:
        if l <= j <= r - 1:
            counter += 1

Submission status: Wrong Answer

Solution code:
N, k = map(int, input().split())
S = input()
start, endl = [], []
for i in range(k):
  a, b = map(int, input().split())
  start.append(a)
  endl.append(b)
record = []
for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    record.append(i)
print(record)
for i in range(len(start)):
  count = 0
  for j in record:
    if start[i]-1 <= j and j < endl[i]-1:
      count += 1
  print(count)

Submission status: Wrong Answer

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

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

for i in range(q):
    l, r = (lists[i][0]-1), (lists[i][1]-1)
    for j in AC_index:
        if l <= j <= r-1:
            counter += 1
    print(counter)
    counter = 0

Submission status: Wrong Answer

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

print(lists)
counter = 0

for i in range(q):
    seq = s[(lists[i][0]-1):(lists[i][1]+1)]
    for j in range(len(seq)-2):
        if seq[j] + seq[j+1] == 'AC':
            counter += 1
        else:
            pass
    print(counter)
    counter = 0

Submission status: Wrong Answer

Solution code:
N, Q = map(int, input().split())
S = input()
for i in range(Q):
  start, end = map(int, input().split())
  j = S[start:end]
  print(j.count('AC'))

Submission status: Wrong Answer

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

AC_appearance = [0] * len(S)
counter = 0
for i in range(1, len(S)):
    if S[i-1] == 'A' and S[i] == 'C':
        counter += 1
    AC_appearance[i] = counter 

print(AC_appearance)

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

Submission status: Wrong Answer

Solution code:
n,q=map(int, raw_input().split())
s=list(raw_input())
cum=0
cum_array=[0]
for p in range(len(s)-1):
    if s[p] == 'A' and s[p+1] == 'C':
        cum+=1
    cum_array.append(cum)
cum_array.append(cum)
print cum_array
for i in range(q):
    l,r=map(int, raw_input().split())
    print(l,r)
    print(cum_array[r-1]-cum_array[l-1])

Submission status: Wrong Answer

Solution code:
import numpy as np

N,Q=map(int,input().split())
y=input()
arr=np.zeros(len(y))
for i in range(len(y)-1):
    if y[i:i+2]=='AC':
        arr[i]=1
    else:
        arr[i]=0
        
arr=arr.cumsum()        
for q in range(Q):
    l,r=map(int,input().split())
    print(int(arr[r-2]-arr[l-1]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N,Q=map(int,input().split())
y=input()
arr=np.zeros(len(y))
for i in range(len(y)-1):
    if y[i:i+2]=='AC':
        arr[i]=1
    else:
        arr[i]=0
        
arr=arr.cumsum()        
for q in range(Q):
    l,r=map(int,input().split())
    print(arr[r-2]-arr[l-1])

Submission status: Wrong Answer

Solution code:
import re
 
n,q=map(int,input().split())
s=str(input())
ans = 0
for _ in range(q):
  l,r=map(int,input().split())
  for i in re.finditer('AC', s[l-1:r]):
  	ans += 1
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,Q=map(int,input().split())
y=input()
arr=[]
for i in range(len(y)-1):
    if y[i:i+2]=='AC':
        arr.append(1)
    else:
        arr.append(0)
        
for q in range(Q):
    l,r=map(int,input().split())
    print(sum(arr[l-1:r]))

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

Solution code:
n,q=list(map(int,input().split()))
s=input()
s_ac=[]
flg=False
for i in range(n):
  if s[i]=="A":
    flg=True
  elif s[i]=="C" and flg:
    s_ac.append(i)
    flg=False
  else:
    flg=False
#print("***"+str(s_ac))

def search(target):
  left=0
  right=len(s_ac)-1
  flg=""
  mid=(right+left)//2
  while left<=right:
    if s_ac[mid]==target:
      flg="M"
      break
    elif s_ac[mid]<target:
      left=mid+1
    elif s_ac[mid]>target:
      right=mid-1
    if s_ac[mid]>target:
      flg="L"
    elif s_ac[mid]<target:
      flg="R"
    mid=(right+left)//2
  return (mid,flg)
  
for i in range(q):
  l,r=list(map(int,input().split()))
  tmp=search(l)
#  print(tmp)
  if tmp[1]!="R":
    left=tmp[0]
  else:
    left=tmp[0]+1
  tmp=search(r-1)
#  print(tmp)
  if tmp[1]!="L":
    right=tmp[0]
  else:
    right=tmp[0]
  print(right-left+1)

Submission status: Wrong Answer

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

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

for i in range(Q):
    if LR[i][0] == 1:
        l = 0
    else:
        l = num_list[LR[i][0]-2]
    if LR[i][1] == N:
        r = num_list[N-2]
    else:
        r = num_list[LR[i][1]-2]
    print(r-l)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

line = np.zeros([n,])
count = 0
for i in range(1,n):
    if (s[i-1:i+1]=="AC"): 
        count += 1
    line[i]=count 
        
print(line)
for i in range(q):
    l,r = map(int,input().split())
    target = line[r-1] - line[l-1]
    print(int(target))

Submission status: Wrong Answer

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

for i in range(Q):
    L = S[LR[i][0]-1:LR[i][1]]
    cnt = 0
    for j in range(len(L)-1,2):
        if L[j:j+2] == 'AC':
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
import itertools
n,q = map(int,input().split())
s = input()
lr = []
for i in range(q): lr.append(list(map(int, input().split())))
ac = [1 if i!=0 and 'AC'==s[i-1:i+1] else 0 for i in range(0,len(s))]
acc = list(itertools.accumulate(ac))
for i in lr: print(acc[i[1]-1], acc[i[0]-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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