Problem p03087 (python)

Fixed submission:
def main():
    n, q = map(int, input().split())
    s = input()

    # 累積出現数を格納: 指定される番号が1始まりなのでズラして格納
    p = [0] * (n+1)
    for i in range(n):
        p[i+1] = p[i] + (1 if s[i:i+2] == "AC" else 0)

    for i in range(q):
        l, r = map(int, input().split())
        # 終端(=l-1)から始端-1(=r-1)の累積出現数を引いた数が指定区間内での出現回数
        print(p[r-1] - p[l-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    pos = []
    for i in range(len(s)):
        if s[i] == 'A' and s[i+1] == 'C':
            i += 1
            pos.append(i)

    for _ in range(q):
        le, re = split_and_to_int(input().strip())
        n = 0
        for v in pos:
            if le <= v < re:
                n += 1
            if re < v:
                break
        res = res + "\n" + str(n)

    print(res.strip())


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    pos = []
    for i, v in enumerate(s):
        if s[i] == 'A' and s[i+1] == 'C':
            pos.append(i+1)
            i += 1

    for _ in range(q):
        le, re = split_and_to_int(input().strip())
        n = len([v for v in pos if le <= v < re])
        res = res + "\n" + str(n)

    print(res.strip())


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-2):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input().strip())
        n = 0
        for i in range(l-1, r-1):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res = res + "\n" + n

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = split_and_to_int(input().strip())
    s = input().strip()

    res = ""
    for _ in range(q):
        l, r = split_and_to_int(input())
        n = 0
        for i in range(l-1, r-1):
            if s[i] == 'A' and s[i+1] == 'C':
                n += 1
                i += 1
        res += f"{n}\n"

    print(res)


def split_and_to_int(s):
    return [int(i) for i in s.split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += str(num_ac) + "\n"

    print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split()]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # num_acs = ""
    # for i in range(q):
    #     li, ri = inputAsIntArr()
    #     num_ac = len([v for v in idxes if li-2 < v < ri-1])
    #     num_acs += str(num_ac) + "\n"

    # print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # num_acs = ""
    # for i in range(q):
    #     li, ri = inputAsIntArr()
    #     num_ac = len([v for v in idxes if li-2 < v < ri-1])
    #     num_acs += str(num_ac) + "\n"

    # print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        # num_ac = len([v for v in idxes if li-2 < v < ri-1])
        # num_acs += str(num_ac) + "\n"

    print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += str(num_ac) + "\n"

    print(num_acs.strip())


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    # 予め探す
    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # 指定された箇所に何件含まれるか
    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += "{}\n".format(str(num_ac))

    print(num_acs)


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
def main():
    n, q = inputAsIntArr()
    s = input()

    # 予め探す
    idxes = []
    for i in range(n):
        if s[i] != 'A':
            continue
        if s[i+1] == 'C':
            idxes.append(i)
            i += 1

    # 指定された箇所に何件含まれるか
    num_acs = ""
    for i in range(q):
        li, ri = inputAsIntArr()
        num_ac = len([v for v in idxes if li-2 < v < ri-1])
        num_acs += f"{str(num_ac)}\n"

    print(num_acs)


def inputAsIntArr():
    return [int(i) for i in input().split(' ')]


if __name__ == '__main__':
    main()