結果
問題 | No.2761 Substitute and Search |
ユーザー | rlangevin |
提出日時 | 2024-05-17 22:25:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,790 bytes |
コンパイル時間 | 250 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 523,288 KB |
最終ジャッジ日時 | 2024-12-20 14:26:46 |
合計ジャッジ時間 | 27,267 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
59,784 KB |
testcase_01 | AC | 44 ms
54,040 KB |
testcase_02 | AC | 41 ms
53,292 KB |
testcase_03 | AC | 41 ms
53,868 KB |
testcase_04 | AC | 3,697 ms
263,056 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 1,685 ms
260,820 KB |
testcase_07 | AC | 1,509 ms
261,776 KB |
testcase_08 | AC | 1,753 ms
261,240 KB |
testcase_09 | AC | 1,619 ms
261,820 KB |
testcase_10 | AC | 1,701 ms
260,720 KB |
testcase_11 | AC | 1,597 ms
261,216 KB |
testcase_12 | AC | 1,670 ms
260,648 KB |
testcase_13 | AC | 1,685 ms
261,832 KB |
testcase_14 | AC | 1,766 ms
261,132 KB |
testcase_15 | MLE | - |
ソースコード
import sys input = sys.stdin.readline class SegmentTree: def __init__(self, n, identity_e, combine_f, ): self._n = n self._size = 1 while self._size < self._n: self._size <<= 1 self._identity_e = identity_e self._combine_f = combine_f self._node = [self._identity_e] * (2 * self._size) def build(self, array): assert len(array) == self._n for index, value in enumerate(array, start=self._size): self._node[index] = value for index in range(self._size - 1, 0, -1): self._node[index] = self._combine_f( self._node[index << 1 | 0], self._node[index << 1 | 1] ) def update(self, index, value): i = self._size + index self._node[i] = value while i > 1: i >>= 1 self._node[i] = self._combine_f( self._node[i << 1 | 0], self._node[i << 1 | 1] ) def fold(self, L, R): L += self._size R += self._size value_L = self._identity_e value_R = self._identity_e while L < R: if L & 1: value_L = self._combine_f(value_L, self._node[L]) L += 1 if R & 1: R -= 1 value_R = self._combine_f(self._node[R], value_R) L >>= 1 R >>= 1 return self._combine_f(value_L, value_R) def __str__(self): temp = [] for i in range(self._n): temp.append(str(self.fold(i, i + 1))) return ' '.join(temp) N, L, Q = map(int, input().split()) base = 4649 mod = 10**9+9 p = [1] * (L + 1) for i in range(L): p[i + 1] = p[i] * base % mod def op(x, y): x0, x1 = divmod(x, base) y0, y1 = divmod(y, base) a = (x0 * p[y1] + y0) % mod b = x1 + y1 return a*base+b T = [SegmentTree(L + 1, 0, op) for i in range(N)] S = [] for i in range(N): S.append(list(input().rstrip())) for j in range(L): T[i].update(j, (ord(S[i][j]) - ord("a"))*base + 1) for q in range(Q): query = list(input().split()) if query[0] == "1": b, c, d = query[1:] b = int(b) - 1 for i in range(N): if S[i][b] == c: S[i][b] = d T[i].update(b, (ord(d) - ord("a"))*base + 1) else: b = query[1] v = 0 for c in b: v = (v*base + ord(c) - ord("a")) % mod ans = 0 for i in range(N): if b[0] != S[i][0] or b[len(b)-1] != S[i][len(b)-1]: continue if v == T[i].fold(0, len(b))//base: ans += 1 print(ans)