結果
問題 |
No.3239 Omnibus
|
ユーザー |
![]() |
提出日時 | 2025-08-14 22:30:37 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,229 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 82,672 KB |
実行使用メモリ | 68,152 KB |
最終ジャッジ日時 | 2025-08-14 22:30:42 |
合計ジャッジ時間 | 4,794 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 1 |
other | RE * 32 |
ソースコード
from sortedcontainers import SortedList class IndexedSet: """SortedList + prefix sum 用に拡張""" def __init__(self): self.sl = SortedList() self.sums = [] def _recalc(self): # prefix sum を更新 self.sums = [] total = 0 for v in self.sl: total += v self.sums.append(total) def add(self, x): self.sl.add(x) self._recalc() def remove(self, x): self.sl.remove(x) self._recalc() def lower_bound(self, x): return self.sl.bisect_left(x) def prefix_sum(self, r): if r == 0: return 0 if r > len(self.sums): return self.sums[-1] return self.sums[r-1] def encode(s, i): return (ord(s[i]) - ord('a')) * 26 * 26 + (ord(s[i+1]) - ord('a')) * 26 + (ord(s[i+2]) - ord('a')) def solve(): import sys input = sys.stdin.readline N, Q = map(int, input().split()) S = input().strip() state = list(S) indices = [None] * (26*26*26) for i in range(N-2): code = encode(S, i) if indices[code] is None: indices[code] = IndexedSet() indices[code].add(i+1) for _ in range(Q): tmp = input().split() q = int(tmp[0]) if q == 1: k = int(tmp[1]) - 1 x = tmp[2] for j in range(k-2, k+1): if 0 <= j < N-2: c = encode(state, j) indices[c].remove(j+1) state[k] = x for j in range(k-2, k+1): if 0 <= j < N-2: c = encode(state, j) if indices[c] is None: indices[c] = IndexedSet() indices[c].add(j+1) else: l = int(tmp[1]) r = int(tmp[2]) a = tmp[3] code = encode(a, 0) if indices[code] is None: print(0) else: p = indices[code].lower_bound(r) s = indices[code].lower_bound(l) ans = indices[code].prefix_sum(p) - indices[code].prefix_sum(s) ans -= (p - s) * (l - 1) print(ans)