結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー horitaka1999horitaka1999
提出日時 2021-10-30 01:32:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,126 ms / 4,000 ms
コード長 2,557 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 196,420 KB
最終ジャッジ日時 2024-10-07 13:16:45
合計ジャッジ時間 32,531 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,660 KB
testcase_01 AC 39 ms
53,256 KB
testcase_02 AC 82 ms
76,236 KB
testcase_03 AC 123 ms
76,908 KB
testcase_04 AC 64 ms
70,232 KB
testcase_05 AC 89 ms
76,440 KB
testcase_06 AC 194 ms
77,740 KB
testcase_07 AC 143 ms
77,244 KB
testcase_08 AC 179 ms
78,268 KB
testcase_09 AC 53 ms
66,308 KB
testcase_10 AC 127 ms
76,668 KB
testcase_11 AC 54 ms
65,404 KB
testcase_12 AC 228 ms
84,776 KB
testcase_13 AC 218 ms
85,644 KB
testcase_14 AC 606 ms
91,204 KB
testcase_15 AC 236 ms
86,992 KB
testcase_16 AC 261 ms
87,340 KB
testcase_17 AC 353 ms
90,256 KB
testcase_18 AC 646 ms
90,120 KB
testcase_19 AC 327 ms
84,712 KB
testcase_20 AC 227 ms
80,976 KB
testcase_21 AC 565 ms
86,648 KB
testcase_22 AC 840 ms
121,792 KB
testcase_23 AC 974 ms
119,004 KB
testcase_24 AC 729 ms
105,840 KB
testcase_25 AC 953 ms
143,668 KB
testcase_26 AC 755 ms
129,044 KB
testcase_27 AC 805 ms
150,180 KB
testcase_28 AC 1,182 ms
151,656 KB
testcase_29 AC 1,111 ms
147,812 KB
testcase_30 AC 1,062 ms
159,876 KB
testcase_31 AC 741 ms
116,016 KB
testcase_32 AC 1,292 ms
190,460 KB
testcase_33 AC 1,266 ms
192,796 KB
testcase_34 AC 1,291 ms
185,592 KB
testcase_35 AC 1,190 ms
172,148 KB
testcase_36 AC 1,282 ms
182,920 KB
testcase_37 AC 1,971 ms
86,364 KB
testcase_38 AC 1,863 ms
86,164 KB
testcase_39 AC 1,854 ms
86,368 KB
testcase_40 AC 2,126 ms
88,384 KB
testcase_41 AC 1,843 ms
86,944 KB
testcase_42 AC 41 ms
59,380 KB
testcase_43 AC 400 ms
196,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def y_plus(m):
    if m == 0 or m == 1:
       return 1
    binM = list(map(int,list(bin(m)[2:])))
    if pow(2,len(binM)) -m == pow(2,len(binM) -1):
        return 1
    return -1 * y_plus(pow(2,len(binM)) - m)
def change(S):
    return ord(S) - ord('a')
X = list(input())
Y = list(input())
xacum = [[0] * 26 for _ in range(len(X)+1)] 
rev_xacum = [[0] * 26 for _ in range(len(X)+1)] 
yacum = [[0] * 26 for _ in range(len(Y)+1)]
rev_yacum = [[0] * 26 for _ in range(len(Y)+1)]
for i in range(len(X)):
    xacum[i+1][change(X[i])] += 1
for i in range(len(Y)):
    yacum[i+1][change(Y[i])] += 1
for i in range(1,len(X)+1):
    for k in range(26):
        xacum[i][k] += xacum[i-1][k]
X.reverse()
for i in range(len(X)):
    rev_xacum[i+1][change(X[i])] += 1
for i in range(1,len(X)+1):
    for k in range(26):
        rev_xacum[i][k] += rev_xacum[i-1][k] 
        
for i in range(1,len(Y)+1):
    for k in range(26):
        yacum[i][k] += yacum[i-1][k]
Y.reverse()
for i in range(len(Y)):
    rev_yacum[i+1][change(Y[i])] += 1
for i in range(1,len(Y)+1):
    for k in range(26):
        rev_yacum[i][k] += rev_yacum[i-1][k]
Z = len(X) + len(Y)
Q = int(input())
ANS = []
for _ in range(Q):
    L,R,C = input().split()
    L = int(L)
    R = int(R)
    l = (L-1) // Z
    tl = L % Z
    if tl == 0:
        tl = Z
    r = R //Z
    tr = R % Z
    ans = (xacum[-1][change(C)] + yacum[-1][change(C)]) * (r-l)
    if y_plus(l+1) == 1:
        if (l+1) % 2 == 1:#+X -> +Y
            ans -= xacum[min(tl-1,len(X))][change(C)] + yacum[max(tl-1-len(X),0)][change(C)]
        else:#-X -> + Y
            ans -= rev_xacum[min(tl-1,len(X))][change(C)] + yacum[max(tl-1-len(X),0)][change(C)]
    else:
        if (l+1) % 2 == 1:#+X -> -Y
            ans -= xacum[min(tl-1,len(X))][change(C)] + rev_yacum[max(tl-1-len(X),0)][change(C)]
        else:#-X -> + Y
            ans -= rev_xacum[min(tl-1,len(X))][change(C)] + rev_yacum[max(tl-1-len(X),0)][change(C)]
    
    if y_plus(r+1) == 1:
        if (r+1) % 2 == 1:#+X -> +Y
            ans += xacum[min(tr,len(X))][change(C)] + yacum[max(tr-len(X),0)][change(C)]
        else:#-X -> + Y
            ans += rev_xacum[min(tr,len(X))][change(C)] + yacum[max(tr-len(X),0)][change(C)]
    else:
        if (r+1) % 2 == 1:#+X -> -Y
            ans += xacum[min(tr,len(X))][change(C)] + rev_yacum[max(tr-len(X),0)][change(C)]
        else:#-X -> + Y
            ans += rev_xacum[min(tr,len(X))][change(C)] + rev_yacum[max(tr-len(X),0)][change(C)]
    ANS.append(ans)
     
for i in range(Q):
    print(ANS[i]) 

            
0