結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー mkawa2
提出日時 2021-10-29 23:21:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,025 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 298,444 KB
最終ジャッジ日時 2024-10-07 12:59:24
合計ジャッジ時間 18,609 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 1 << 63
# md = 998244353
md = 10**9+7

from bisect import bisect
from collections import Counter
from functools import lru_cache

def cntc(s):
    res = []
    cnt = Counter()
    res.append(cnt.copy())
    for c in s:
        c = ord(c)-97
        cnt[c] += 1
        res.append(cnt.copy())
    return res

s = SI()
t = SI()
x = len(s)
y = len(t)
cc = cntc(s)
tc = cntc(t)
itc = cntc(t[::-1])

ww = [x]
aa = [1]
bb = [0]
cur = x
while ww[-1] < 10**9+5:
    cur = cur*2+y
    ww.append(cur)
    aa.append(aa[-1]*2)
    bb.append(bb[-1]*2+1)
# print(ww)
# print(aa)
# print(bb)

@lru_cache(None)
def solve(r, c):
    res = 0
    si = bisect(ww, r)-1
    rev = False
    for i in range(si, -1, -1):
        w = ww[i]
        if w > r:
            rev = False
            continue
        if w == r:
            res += aa[i]*cc[-1][c]+bb[i]*tc[-1][c]
            r = 0
            break
        res += aa[i]*cc[-1][c]+bb[i]*tc[-1][c]
        if r-w <= y:
            if rev:
                res += itc[r-w][c]
            else:
                res += tc[r-w][c]
            r = 0
            break
        else:
            res += tc[-1][c]
            r -= w+y
            rev = True

    res += cc[r][c]
    return res

for _ in range(II()):
    l, r, c = SI().split()
    l = int(l)-1
    r = int(r)
    c = ord(c)-97
    # print(solve(r, c),solve(l, c))
    ans = solve(r, c)-solve(l, c)
    print(ans)
0