結果
問題 | No.2020 Sum of Common Prefix Length |
ユーザー |
👑 |
提出日時 | 2022-07-22 22:40:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,477 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 81,872 KB |
実行使用メモリ | 88,576 KB |
最終ジャッジ日時 | 2024-07-04 07:13:03 |
合計ジャッジ時間 | 13,413 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 TLE * 1 -- * 24 |
ソースコード
class Node: def __init__(self): self.nex = {} self.ind = [] self.tot = 0 n = int(input()) V0 = Node() Vs = [None] * n ans = [0] * n SS = [] for i in range(n): S = input() SS.append([ord(s) - 97 for s in S]) V = V0 for s in SS[i]: if s not in V.nex: V.nex[s] = Node() V = V.nex[s] V.tot += 1 Vs[i] = V B = 700 for i, S in enumerate(SS): V = V0 flg = len(S) >= B for s in S: V = V.nex[s] ans[i] += V.tot if flg: V.ind.append(i) Q = int(input()) for _ in range(Q): query = input().split() if query[0] == "1": i = int(query[1]) - 1 s = query[2] s = ord(s) - 97 SS[i].append(s) V = Vs[i] if s not in V.nex: V.nex[s] = Node() V = V.nex[s] V.tot += 1 for j in V.ind: ans[j] += 1 le = len(SS) if le < B: pass elif le == B: ans[i] = 0 V = V0 for s in SS[i]: V = V.nex[s] ans[i] += V.tot V.ind.append(i) else: V.ind.append(i) ans[i] += V.tot Vs[i] = V else: i = int(query[1]) - 1 le = len(SS[i]) if le < B: ans[i] = 0 V = V0 for s in SS[i]: V = V.nex[s] ans[i] += V.tot print(ans[i])