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: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, q = map(int, readline().split())
    s = readline().rstrip().decode()
    ac = []    
    cnt = 0
    for i in range(1, n+1):
        if (s[i-1] == 'A') and (s[i] == 'C'):
            cnt += 1
            ac.append(cnt)
        else:
            ac.append(cnt)
    query = []
    for _ in range(q):
        l, r = map(int, readline().split())
        l -= 1
        r -= 1
        print(ac[r]-ac[l])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n, q = map(int, readline().split())
    s = readline().rstrip().decode()
    ac = []    
    cnt = 0
    for i in range(n+1):
        if (s[i-1] == 'A') and (s[i] == 'C'):
            cnt += 1
            ac.append(cnt)
        else:
            ac.append(cnt)
    query = []
    for _ in range(q):
        l, r = map(int, readline().split())
        l -= 1
        r -= 1
        print(ac[r]-ac[l])
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for _ in range(q):
    li, ri = map(int, input().split())
    print(cnt[ri - 1] - cnt[li - 1])

Submission status: Runtime Error

Solution code:
import numpy as np

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

S = input()

ac = np.zeros(N-1)

for i in range(Q):
	l, r = map(int, input().split())
    print(S.count('AC'))
	#print(int(sum(ac[l-1:r-2])))

Submission status: Runtime Error

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

ans = []

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

print(*ans, sep="\n")

Submission status: Runtime Error

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

a = [0 for i in range(N)]
b = [0 for i in range(N)]

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    a[i] = 1
    b[i+1] = 1
    
def cumsum(xs):
  result = [xs[0]]
  for x in xs[1:]:
    result.append(result[-1] + x)
  return result

A = cumsum(a)
B = cumsum(b)

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

Submission status: Runtime Error

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

substrs = []
s_append = substrs.append
for i in range(Q):
    l, r = map(int, input().split())
    s_append(S[l - 1:r])

# check
for substr in substrs:
    substr_len = len(substr)
    AC_cnt = sum(
        [
            1
            for i in range(0, substr_len - 1)
            if substr[i:i + 2] == "AC"
        ]
    )

    print(AC_cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for j in range(n):
    if l[j] == 'A' and l[j+1] == 'C':
        l[j] = 'a'
        l[j+1] = 'c'

import collections   
a_l=[]
b_l=[]
for i in range(q):
    a,b=map(int,input().split())
    a_l.append(a)
    b_l.append(b)

    
for i in range(q):
    c=collections.Counter(l[a_l[i]-1:b_l[i]])
    if l[b_l[i]-1] != 'a':
        print(c['a'])
    else:
        print(c['a']-1)

Submission status: Runtime Error

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

for j in range(n):
    if l[j] == 'A' and l[j+1] == 'C':
        l[j] = 1
        l[j+1] = 2

import collections   
a_l=[]
b_l=[]
for i in range(q):
    a,b=map(int,input().split())
    a_l.append(a)
    b_l.append(b)

    
for i in range(q):
    c=collections.Counter(l[a_l[i]-1:b_l[i]])
    if l[b_l[i]-1] != 1:
        print(c[1])
    else:
        print(c[1]-1)

Submission status: Runtime Error

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

for j in range(n):
    if l[j] == 'A' and l[j+1] == 'C':
        l[j] = 1
        l[j+1] = 2

import collections   
for i in range(q):
    a,b=map(int,input().split())
    
    c=collections.Counter(l[a-1:b])
        
    if l[b-1] != 1:
        print(c[1])
        continue
    else:
        print(c[1]-1)
        continue

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
l=list(str(input()))
#print(l)
for j in range(n):
    if l[j] == 'A' and l[j+1] == 'C':
        l[j] = 1
        l[j+1] = 2
#print(l)

import collections   
for i in range(q+1):
    a,b=map(int,input().split())
    #print('a',a,'b',b)
    #k = 0
    #for l[k] in l[a-1:b]:
    c=collections.Counter(l[a-1:b])
        #print('l[k]',l[k],'l[a-1:b]',l[a-1:b])
    if l[b-1] != 1:
        #print('a-1',a-1,'b',b)
        #print('l[a-1]',l[a-1],'l[b]',l[b])
        print(c[1])
        continue
    else:
        #print('a-1',a-1,'b',b)
        #print('l[a-1]',l[a-1],'l[b]',l[b])
        print(c[1]-1)
        continue

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(sys.stdin.readline() for _ in range(n)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# INF = float("inf")
import sys,collections
N,Q = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
S = sys.stdin.readline().rstrip()
se = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(Q)) # multi line with multi param

INF = float("inf")
com = [0]*(N+1)

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

for s,e in se:
    print(com[e-1] - com[s-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

start_list = [0]*(n)
end_list = [0]*(n+1)

num = 0
for i in range(n):
    if s[i] == "A" and s[i+1] == "C":
        num += 1
    start_list[i] = num
    end_list[i+1] = num
start_list.insert(0,0)

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

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N)
for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N-1)
for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])

Submission status: Runtime Error

Solution code:
from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N-1)
for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
print(R)
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N+1):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

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

Submission status: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]
#dp[i]はi番目までの文字で'AC'がいくつあるか
dp = [0] * (N+1)
for i in range(1, N+1):
    if S[i-1] == 'A' and S[i] == 'C':
        dp[i] = dp[i-1] + 1
    else:
        dp[i] = dp[i-1]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

    for j in range(l-1, r):
        if s[j]=="A" and s[j+1]=="C":
            if j==r-1:
                pass
            else:
                cnt+=1

    ans.append(cnt)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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 accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()

lis = [0]*N

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

lis_acc = list(accumulate(lis))

for _ in range(Q):
	l, r = MAP()
	print(lis_acc[r-1] - lis_acc[l-1])

Submission status: Runtime Error

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

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

for x in lst:
    print(cum[x[1]-1] - cum[x[0]-1])

Submission status: Runtime Error

Solution code:
N,M = list(map(int,input().split()))
l_n = list(input())
l_a = [0] * (N+1)
for i in range(N):
    l_a[i+1] = l_a[i] + 1 if l_n[i] == "A" and l_n[i+1] == "C" else l_a[i]
for i in range(M):
    l,r = list(map(int,input().split()))
    print(l_a[r-1]-l_a[l-1])

Submission status: Runtime Error

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

L = [0] * (N + 1)

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


for i in range(Q):
    print(L[lr[i][1] - 1] - L[lr[i][0] - 1])

Submission status: Runtime Error

Solution code:
import math
# import itertools
# import statistics
# import numpy as np
#n = int(input())
n, q = list(map(int, input().split()))
#b = list(map(int, input().split()))
s = input()
lr = []
for i in range(q):
    x, y = list(map(int, input().split()))
    lr.append([x, y])

ac_count = [0]*int(len(s))
point = 0
for i in range(len(s)):
    if s[i] == "A" and s[i+1] == "C":
        ac_count[i] += point+0.5
        point += 0.5
        ac_count[i+1] += point+0.5
        point += 0.5
    else:
        ac_count[i] = point

for i in range(q):
    print(math.floor(ac_count[lr[i][1]-1])-math.floor(ac_count[lr[i][0]-1]))

Submission status: Runtime Error

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

def ac_count(n):
    count=0
    for i in range(n):
        if S[i] == 'A' and S[i+1] == 'C':
            count += 1

    if S[n-1] =='A' and S[n] =='C':
        count -=1
    return count

list = []
for i in range(Q):
    l, r = map(int, input().split())
    ac=ac_count(r)-ac_count(l)
    list.append(ac)

for i in range(len(list)):
    print(list[i])

Submission status: Runtime Error

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

cumulatives = [0] * (N + 1)

for i in range(N):
  # 右隣にCが来るAの数を数える
  if S[i:i + 2] == 'AC':
    cumulatives[i + 1] = cumulatives[i] + 1
  else:
    cumulatives[i + 1] = cumulatives[i]

for i in range(Q):  
  l, r = map(lambda x: int(x) - 1, input().split())  # index 合わせる
  # 右隣の文字がCでない場合は条件を満たさないので右端を1左にずらす（開区間と考える）
  print(cumulatives[r] - cumulatives[l])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, q = map(int, input().split())
s_list = list(input())
l_r_list = [list(map(int, input().split())) for _ in range(q)]
c_sum= [0]
su = 0
for i in range(n):
    if s_list[i] == "A" and s_list[i + 1] == "C":
        su += 1
    c_sum.append(su)
for l, r in l_r_list:
    print(c_sum[r - 1] - c_sum[l - 1])

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,q = readInts()
    s = input()
    for i in range(n):
        i,r = readInts()
        i -=1 # zero based index
        S = s[i:r]
        print(S.count('AC'))

if __name__ == '__main__':
  main()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#abc122_b
#word = 'HATAGAYA'
#word = 'SHINJUKU'
word_len, query_num = [int(i) for i in input().split(' ')]
word = input()
#word = 'ACACTACG'
#chl = ['A','C','G','T']
queries = [[int(j) for j in input().split()] for i in range(query_num)]
lmax = 0
temp = 0
stack = []
for i in queries: # 3queries, i = (3,7)
    l_max = 0
    temp = 0
    for j in range(i[0],i[1] + 1):
        if word[j] == 'C':
            if stack[0] == 'A':
                temp += 1
        else:
            stack.append(word[j])
    res_list.append(temp)

for i in stack:
    print(i)

Submission status: Runtime Error

Solution code:
#abc122_b
#word = 'HATAGAYA'
#word = 'SHINJUKU'
word_len, query_num = [int(i) for i in input().split(' ')]
word = input()
#word = 'ACACTACG'
#chl = ['A','C','G','T']
queries = [[int(j) for j in input().split()] for i in range(query_num)]
lmax = 0
temp = 0
stack = []
for i in queries: # 3queries, i = (3,7)
    l_max = 0
    temp = 0
    for j in range(i[0],i[1] + 1):
        if word[j] == 'C':
            if stack[0] == 'A'
                temp += 1
        else len(word[j]) == 0:
             stack.append(word[j])
    res_list.append(temp)
for i in stack:
    print(i)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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)
for j in range(Q):
  print(str.count("AC",L[j].R[j]+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Q = map(int,input().split())
S = input().rstrip()
LR = [map(int,input().split()) for _ in range(Q)]

A = [0]*(N+1)
for i in range(N):
    if S[i]=="A" and S[i+1]=="C":
        A[i+1] = 1
for i in range(i):
    A[i+1] += A[i]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]
s1=len(list(s))
l=[0]*(s1-1)
for i in range(s1):
    if s[i]=='A' and s[i+1]=='C':
        l[i]+=1
for j in range(q):
    print( sum( l [lr[j][0]-1:lr[j][1]-1] ))

Submission status: Runtime Error

Solution code:
n,q=map(int,input().split())
s=input()
lr=[list(map(int,input().split())) for _ in range(q)]
s1=len(list(s))
l=[0]*(s1-1)
for i in range(s1//2):
    if s[2*i]=='A' and s[2*i+1]=='C':
        l[2*i]+=1
    if s[2*i+1]=='A' and s[2*(i+1)]=='C':
        l[2*i+1]+=1
for j in range(q):
    print( sum( l [lr[j][0]-1:lr[j][1]-1] ))

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s= input()
ans = [int(s[i:i+2]=='AC') for i in range(n)]
from itertools import accumulate
ans = list(accumulate(ans))
for _ in range(q):
  l,r = map(int,input().split())
  print(ans[r]-ans[l])

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
readline = sys.stdin.readline
read = sys.stdin.read

import bisect
n, q = map(int, readline().split())
s = readline().rstrip()
a = []
for i in range(len(s)):
	if s[i] == 'A' and s[i + 1] == 'C':
		a.append(i)
for _ in range(q):
	l, r = map(int, readline().split())
	l -= 1
	r -= 2
	print(bisect.bisect_right(a, r) - bisect.bisect_left(a, l))

Submission status: Runtime Error

Solution code:
# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (2 * 10**5 + 10)
idx = 1
while idx <= len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])

Submission status: Runtime Error

Solution code:
# 累積和
n, q = map(int, input().split())
s = input()
arr = [0] * (len(s) + 1)
idx = 1
while idx <= len(s):
    if s[idx - 1] == "A" and s[idx] == "C":
        arr[idx] += 1
    idx += 1
for i in range(1, len(arr)):
    arr[i] += arr[i - 1]
for _ in range(q):
    l, r = map(int, input().split())
    print(arr[r - 1] - arr[l - 1])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
anslist = []
anslist2 = [0]*q
for i in range(n):
  if s[i] == 'A' and s[i+1] == 'C':
    anslist.append([i+1,i+2])
for i in range(q):
  l,r = map(int,input().split())
  cnt = 0
  for j in range(len(anslist)):
    if l <= anslist[j][0] and anslist[j][1] <= r:
      cnt += 1
  anslist2[i] = cnt
for i in range(q):
  print(anslist2[i])

Submission status: Runtime Error

Solution code:
n,q = map(int,input().split())
s = input()
lr = [list(map(int,input().split())) for i in range(q)]
anslist = []
for i in range(n):
  if s[i] == 'A' and s[i+1] == 'C':
    anslist.append([i,i+1])
for i in range(q):
  cnt = 0
  for j in range(len(anslist)):
    if lr[i][0]-1 <= anslist[j][0] and anslist[j][1] <= lr[i][1]-1:
      cnt += 1
  print(cnt)

Submission status: Runtime Error

Solution code:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in (0,N-1)[::-1]:
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R


for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

Submission status: Runtime Error

Solution code:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0] * N
Rsub = [0] * N
L = 0
R = 0


for k in range(1,N):
  if SS[k-1] == "A" and SS[k] == "C":
    L += 1
  Lsub[k] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R
  

for i in range(Q):
  L, R = map(int, input().split())
  print(Rsub[0] - Lsub[L-1] - Rsub[R-1])

Submission status: Runtime Error

Solution code:
N, Q  = map(int, input().split())
S = list(input())
Lsub = [0]*N
Rsub = [0]*N
L = 0
R = 0


for j in range(1,N):
  if SS[j-1] == "A" and SS[j] == "C":
    L += 1
  Lsub[j] = L

for j in reversed(range(0,N-1)):
  if SS[j] == "A" and SS[j+1] == "C":
    R += 1
  Rsub[j] = R



ans = [0] * Q

for i in range(Q):
  L, R = map(int, input().split())
  ans[i] = Rsub[0] - Lsub[L-1] - Rsub[R-1]


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

Submission status: Runtime Error

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  n, q = map(int, readline().split())
  s = input()
  t = [0] *(n=1)
  for i in range(n):
    t[i+1] = t[i] + (a if s[i:i+2] == 'AC' else 0)
  for i in range(q):
    l, r = map(int, readline().split())
    print(t[r-1] - t[l-1])
  
  
if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
import math

n,q=map(int,input().split())
S=input()
A=[]
flag=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            A.append(i-1)
        flag=0
    else:
        flag=0
a=len(A)
        
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    low=0
    high=a-1
    if A[0]>=l:
        cntl=0
    elif A[a-1]<l:
        print(0)
        continue
    else:
        while high-low>1:
            now=math.ceil((high+low)/2)
            if A[now]>=l:
                high=now
            else:
                low=now
        cntl=high
    low=0
    high=a-1
    if A[a-1]+1<=r:
        cntr=a-1
    elif A[0]+1>r:
        print(0)
        continue
    else:
        while high-low>1:
            now=(high+low)//2
            if A[now]+1<=r:
                low=now
            else:
                high=now
        cntr=low
    if cntr>=cntl:
        print(cntr-cntl+1)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
import math

n,q=map(int,input().split())
S=input()
A=[]
flag=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            A.append(i-1)
        flag=0
    else:
        flag=0
a=len(A)
        
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    low=0
    high=a-1
    if A[0]>=l:
        cntl=0
    elif A[a-1]<l:
        print(0)
        continue
    else:
        while high-low>1:
            now=math.ceil((high+low)//2)
            if A[now]<=l:
                high=now
            else:
                low=now
        cntl=high
    low=0
    high=a-1
    if A[a-1]+1<=r:
        cntr=a-1
    elif A[0]+1>r:
        print(0)
        continue
    else:
        while high-low>1:
            now=(high+low)//2
            if A[now]+1<=r:
                low=now
            else:
                high=now
        cntr=low
    print(cntr-cntl+1)

Submission status: Runtime Error

Solution code:
import math

n,q=map(int,input().split())
S=input()
A=[]
flag=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            A.append(i-1)
        flag=0
    else:
        flag=0
a=len(A)
print(A)
        
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    low=0
    high=a-1
    if A[0]>=l:
        cntl=0
    elif A[a-1]<l:
        print(0)
        continue
    else:
        while high-low>1:
            now=math.ceil((high+low)//2)
            if A[now]<=l:
                high=now
            else:
                low=now
        cntl=high
    low=0
    high=a-1
    if A[a-1]+1<=r:
        cntr=a-1
    elif A[0]+1>r:
        print(0)
        continue
    else:
        while high-low>1:
            now=(high+low)//2
            if A[now]+1<=r:
                low=now
            else:
                high=now
        cntr=low
    print(cntr-cntl+1)

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

a=['']*(n+1)
for i in range(n):
    a[i+1]=a[i]+s[i]    

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

Submission status: Runtime Error

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

C = [0 for _ in range(N+1)]
#C[i]:i文字目までで"AC"が出てくる回数
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        C[i+2] += 1

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

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

Submission status: Runtime Error

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

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