結果
| 問題 | No.3638 Itsuki |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-26 02:01:07 |
| 言語 | PyPy3 (8.0.1 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 3,633 bytes |
| 記録 | |
| コンパイル時間 | 87 ms |
| コンパイル使用メモリ | 64,232 KB |
| 実行使用メモリ | 76,456 KB |
| 最終ジャッジ日時 | 2026-11-26 02:01:18 |
| 合計ジャッジ時間 | 11,161 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サンプル | 0 % | AC * 2 |
| 小課題1 | 10 % | AC * 5 |
| 小課題2 | 50 % | TLE * 1 -- * 5 |
| 小課題3 | 40 % | AC * 7 TLE * 1 -- * 10 |
| 合計 | 10 点 |
ソースコード
# https://yukicoder.me/problems/no/3638
from collections import deque
B = 30
H = 9007199254740997
# ソースコードの出典URL: https://github.com/LyricalMaestro/at_coder_snippets/blob/af67863a2fe7f16cce8325bbc531f89968bfa525/src/segment_tree.py
class SegmentTree:
"""
非再帰版セグメント木。
更新は「加法」、取得は「最大値」のもの限定。
"""
def __init__(self, init_array):
n = 1
while n < len(init_array):
n *= 2
self.size = n
self.array = [0] * (2 * self.size)
self.weights = [0] * (2 * self.size)
for i, a in enumerate(init_array):
self.array[self.size + i] = a
self.weights[self.size +i] = 1
pow_b = 1
self.pow_b_list = [0] * (len(init_array) + 1)
for i in range(len(init_array) + 1):
self.pow_b_list[i] = pow_b
pow_b *= B
pow_b %= H
end_index = self.size
start_index = end_index // 2
while start_index >= 1:
for i in range(start_index, end_index):
self.weights[i] = self.weights[2 * i] + self.weights[2 * i + 1]
self.array[i] = self._op(self.array[2 * i], self.array[2 * i + 1], self.weights[2 * i + 1])
end_index = start_index
start_index = end_index // 2
def _op(self, left , right, r_weight):
x = left * self.pow_b_list[r_weight]
x %= H
x += right
x %= H
return x
def set(self, x, a):
index = self.size + x
self.array[index] = a
while index > 1:
index //= 2
self.array[index] = self._op(self.array[2 * index], self.array[2 * index + 1], self.weights[2 * index + 1])
def get_hash(self, l, r):
L = self.size + l; R = self.size + r
r_queue = deque()
l_queue = deque()
# 2. 区間[l, r)の最大値を求める
s = 0
while L < R:
if R & 1:
R -= 1
r_queue.appendleft(R)
if L & 1:
l_queue.append(L)
L += 1
L >>= 1; R >>= 1
while len(l_queue) > 0:
l = l_queue.popleft()
s = self._op(s, self.array[l], self.weights[l])
while len(r_queue) > 0:
l = r_queue.popleft()
s = self._op(s, self.array[l], self.weights[l])
return s
def main():
N, Q = map(int, input().split())
S = input()
queries = []
for _ in range(Q):
values = input().split()
queries.append(values)
pow_b_list = [0] * (N + 1)
pow_b = 1
for i in range(N + 1):
pow_b_list[i] = pow_b
pow_b *= B
pow_b %= H
s_list = [ord(s) - ord("a") + 1 for s in S]
seg_tree = SegmentTree(s_list)
for values in queries:
if values[0] == "1":
_, i, c = values
i = int(i) - 1
c = ord(c) - ord("a") + 1
seg_tree.set(i, c)
else:
_, t = values
hash0 = 0
for t0 in t:
hash0 *= B
hash0 %= H
hash0 += ord(t0) - ord("a") + 1
hash0 %= H
is_ok = False
for i in range(0, N + 1 - len(t)):
x = seg_tree.get_hash(i, i + len(t))
if x == hash0:
is_ok = True
break
if is_ok:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()