A56 - String Hash
提出
TLE
code: python
n, q = map(int, input().split())
s = input()
for query in abcd:
a, b, c, d = query0, query1, query2, query3, print("Yes")
else:
print("No")
解答
code:python
N, Q = map(int, input().split())
S = input()
# 文字を数値に変換
# ord(c) で文字 c の文字コード(ASCII コード)を取得
T = list(map(lambda c: ord(c) - ord('a') + 1, S))
# 100 の n 乗を前計算
MOD = 2147483647 # 適当な素数
power100 = None * (N + 1) for i in range(N):
power100i + 1 = power100i * 100 % MOD for i in range(N):
# ハッシュ値を求める関数
# C++ とは異なり、(負の値)% M (M >= 1) も 0 以上 M-1 以下になることに注意
def hash_value(l, r):
for a, b, c, d in queries:
hash1 = hash_value(a, b)
hash2 = hash_value(c, d)
if hash1 == hash2:
print("Yes")
else:
print("No")