結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー tamatotamato
提出日時 2021-10-29 22:27:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,801 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 116,676 KB
最終ジャッジ日時 2024-04-16 15:18:58
合計ジャッジ時間 11,821 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,608 KB
testcase_01 AC 41 ms
52,864 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 172 ms
78,080 KB
testcase_38 AC 170 ms
78,108 KB
testcase_39 AC 170 ms
78,108 KB
testcase_40 AC 167 ms
78,136 KB
testcase_41 AC 171 ms
77,728 KB
testcase_42 AC 39 ms
52,736 KB
testcase_43 AC 220 ms
116,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    X = input().rstrip('\n')
    Y = input().rstrip('\n')
    NX = len(X)
    NY = len(Y)
    NXY = NX + NY

    cs_X = [[0] * (NX+1) for _ in range(26)]
    for i in range(NX):
        x = X[i]
        for j in range(26):
            c = chr(j + 97)
            if c == x:
                cs_X[j][i+1] = cs_X[j][i] + 1
            else:
                cs_X[j][i+1] = cs_X[j][i]
    cs_Y = [[0] * (NY+1) for _ in range(26)]
    for i in range(NY):
        y = Y[i]
        for j in range(26):
            c = chr(j + 97)
            if c == y:
                cs_Y[j][i+1] = cs_Y[j][i] + 1
            else:
                cs_Y[j][i+1] = cs_Y[j][i]

    def calc(i, c):
        j = ord(c) - 97
        p = i // NXY
        res = p * (cs_X[j][-1] + cs_Y[j][-1])
        q = i % NXY
        
        if q == 0:
            return res

        # X
        pp = i // (2 * NXY)
        if pp & 1:
            # rev
            res += cs_X[j][NX] - cs_X[j][max(0, NX - q)]
        else:
            res += cs_X[j][min(q, NX)]

        # Y
        if q > NX:
            ppp = p + 1
            cnt = 0
            while True:
                r = 1 << (ppp.bit_length())
                ppp_new = r - ppp
                if ppp_new == ppp:
                    break
                ppp = ppp_new
                cnt += 1
            qq = q - NX
            if cnt & 1:
                # rev
                res += cs_Y[j][NY] - cs_Y[j][NY - qq]
            else:
                res += cs_Y[j][qq]
        return res

    Q = int(input())
    for _ in range(Q):
        l, r, c = input().split()
        l = int(l)
        r = int(r)
        print(calc(r, c) - calc(l-1, c))


if __name__ == '__main__':
    main()
0