結果
問題 | No.2020 Sum of Common Prefix Length |
ユーザー | souta-1326 |
提出日時 | 2022-05-24 23:23:29 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,095 bytes |
コンパイル時間 | 145 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 318,140 KB |
最終ジャッジ日時 | 2024-09-20 14:35:59 |
合計ジャッジ時間 | 24,213 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,120 KB |
testcase_01 | AC | 36 ms
52,864 KB |
testcase_02 | AC | 36 ms
52,992 KB |
testcase_03 | AC | 120 ms
78,264 KB |
testcase_04 | AC | 118 ms
77,864 KB |
testcase_05 | AC | 115 ms
78,320 KB |
testcase_06 | AC | 119 ms
78,436 KB |
testcase_07 | AC | 350 ms
95,232 KB |
testcase_08 | AC | 349 ms
95,104 KB |
testcase_09 | AC | 350 ms
95,360 KB |
testcase_10 | AC | 344 ms
94,848 KB |
testcase_11 | AC | 351 ms
95,232 KB |
testcase_12 | AC | 361 ms
95,232 KB |
testcase_13 | AC | 349 ms
95,616 KB |
testcase_14 | AC | 358 ms
95,232 KB |
testcase_15 | AC | 482 ms
138,880 KB |
testcase_16 | AC | 483 ms
139,008 KB |
testcase_17 | AC | 495 ms
154,148 KB |
testcase_18 | AC | 428 ms
131,688 KB |
testcase_19 | AC | 441 ms
135,796 KB |
testcase_20 | AC | 734 ms
252,892 KB |
testcase_21 | AC | 654 ms
221,412 KB |
testcase_22 | AC | 651 ms
221,544 KB |
testcase_23 | AC | 694 ms
219,132 KB |
testcase_24 | AC | 701 ms
239,588 KB |
testcase_25 | AC | 697 ms
238,112 KB |
testcase_26 | AC | 1,775 ms
260,608 KB |
testcase_27 | AC | 37 ms
52,608 KB |
testcase_28 | AC | 416 ms
110,464 KB |
testcase_29 | AC | 404 ms
111,488 KB |
testcase_30 | AC | 406 ms
109,312 KB |
testcase_31 | AC | 1,245 ms
274,420 KB |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | AC | 488 ms
137,804 KB |
testcase_35 | AC | 479 ms
137,832 KB |
testcase_36 | AC | 1,216 ms
236,872 KB |
testcase_37 | AC | 527 ms
158,888 KB |
ソースコード
class Fenwick_Tree: def __init__(self,N:int): self.N = N self.dat = [0]*(N+1) def add(self,p:int,x:int): p += 1 while p <= self.N: self.dat[p] += x p += p&-p def _sum(self,r:int): s = 0 while r: s += self.dat[r] r -= r&-r return s sum = lambda self,l,r:self._sum(r)-self._sum(l) class EulerTour: def __init__(self,G): self.N = len(G) self.begin = [0]*self.N self.end = [0]*self.N self.B_v = Fenwick_Tree(self.N*2) cnt = 0 f = 0 itr = [0]*self.N par = [0]*self.N par[f] = -1 while f != -1: if itr[f] == 0: self.begin[f] = cnt;cnt+=1 if itr[f] == len(G[f]): self.end[f] = cnt;cnt+=1 f = par[f] continue par[G[f][itr[f]]] = f itr[f]+=1 f = G[f][itr[f]-1] def add(self,p:int,num:int =1): self.B_v.add(self.begin[p],num) self.B_v.add(self.end[p],-num) def query(self,p:int): return self.B_v.sum(0,self.begin[p]+1) def main(): N = int(input()) S = [input() for _ in range(N)] Q = int(input()) T = [0]*Q X = [0]*Q C = [""]*Q for i in range(Q): I = input().split() T[i] = int(I[0]);X[i] = int(I[1])-1 if T[i]==1:C[i] = I[2] path = [[0] for _ in range(N)] node = [""] nex = [[-1]*26] S2 = S[:] for i in range(Q): if T[i] == 1: S2[X[i]] += C[i] for i in range(N): now_node = 0 for c in S2[i]: z = ord(c)-97 if nex[now_node][z] == -1: nex[now_node][z] = len(node) node.append(c) nex.append([-1]*26) now_node = nex[now_node][z] path[i].append(now_node) V = len(node) G = [[] for _ in range(V)] for i in range(V): for j in range(26): if nex[i][j] != -1: G[i].append(nex[i][j]) Eul = EulerTour(G) len_S = list(map(len,S)) for i in range(N): for j in range(len_S[i]):Eul.add(path[i][j+1]) for i in range(Q): if T[i] == 1: len_S[X[i]] += 1 Eul.add(path[X[i]][len_S[X[i]]]) else: print(Eul.query(path[X[i]][len_S[X[i]]])) if __name__ == "__main__": main()