結果
問題 | No.2611 Count 01 |
ユーザー | Mitarushi |
提出日時 | 2024-01-19 17:46:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,345 ms / 6,000 ms |
コード長 | 2,739 bytes |
コンパイル時間 | 809 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 269,084 KB |
最終ジャッジ日時 | 2024-09-28 03:37:22 |
合計ジャッジ時間 | 85,307 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
53,248 KB |
testcase_01 | AC | 40 ms
52,352 KB |
testcase_02 | AC | 52 ms
61,824 KB |
testcase_03 | AC | 4,162 ms
268,628 KB |
testcase_04 | AC | 4,201 ms
268,732 KB |
testcase_05 | AC | 4,179 ms
268,752 KB |
testcase_06 | AC | 4,227 ms
268,460 KB |
testcase_07 | AC | 4,045 ms
268,860 KB |
testcase_08 | AC | 4,115 ms
268,628 KB |
testcase_09 | AC | 4,122 ms
268,464 KB |
testcase_10 | AC | 3,970 ms
268,828 KB |
testcase_11 | AC | 4,109 ms
268,528 KB |
testcase_12 | AC | 3,943 ms
269,084 KB |
testcase_13 | AC | 4,076 ms
268,688 KB |
testcase_14 | AC | 4,012 ms
268,744 KB |
testcase_15 | AC | 4,122 ms
268,968 KB |
testcase_16 | AC | 4,238 ms
268,896 KB |
testcase_17 | AC | 4,201 ms
268,532 KB |
testcase_18 | AC | 4,123 ms
268,856 KB |
testcase_19 | AC | 4,132 ms
268,336 KB |
testcase_20 | AC | 4,092 ms
268,828 KB |
testcase_21 | AC | 4,345 ms
268,580 KB |
testcase_22 | AC | 4,340 ms
268,608 KB |
ソースコード
class SegmentTree: def __init__(self, n, e): n2 = 1 while n2 < n: n2 *= 2 self.n = n2 self.data = [e] * (n2 * 2) def build(self, a): for i, x in enumerate(a): self.data[i + self.n] = x for i in range(self.n - 1, 0, -1): self.data[i] = self.data[i * 2] + self.data[i * 2 + 1] def update(self, i, x): k = i + self.n self.data[k] = x while k > 1: k //= 2 self.data[k] = self.data[k * 2] + self.data[k * 2 + 1] def query(self, l, r, ls, rs): l += self.n r += self.n while l < r: if l & 1: ls += self.data[l] l += 1 if r & 1: r -= 1 rs = self.data[r] + rs l //= 2 r //= 2 return ls + rs MOD = 998244353 class Vec: def __init__(self, a): self.a = a def __add__(self, other): if isinstance(other, Matrix): result = self.a[:] for i in range(len(self.a)): for j in range(i): result[j] += self.a[i] * other.a[i * (i - 1) // 2 + j] for i in range(len(self.a)): result[i] %= MOD return Vec(result) return sum(x * y for x, y in zip(self.a, other.a)) % MOD class Matrix: size = 6 def __init__(self, a): self.a = a def __add__(self, other): if isinstance(other, Vec): result = other.a[:] for i in range(self.size): for j in range(i): result[i] += self.a[i * (i - 1) // 2 + j] * other.a[j] result[i] %= MOD return Vec(result) result = [i + j for i, j in zip(self.a, other.a)] for i in range(self.size): for j in range(i): ij = i * (i - 1) // 2 + j for k in range(j + 1, i): result[ij] += self.a[i * (i - 1) // 2 + k] * other.a[k * (k - 1) // 2 + j] result[ij] %= MOD return Matrix(result) node = [ Matrix([1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1]), Matrix([1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1]), ] identity = Matrix([0 for _ in range(15)]) n, q = map(int, input().split()) s = input() s_seq = [int(x) for x in s] st = SegmentTree(n, identity) st.build([node[x] for x in s_seq]) for _ in range(q): t, *args = map(int, input().split()) if t == 1: i = args[0] - 1 s_seq[i] = 1 - s_seq[i] st.update(i, node[s_seq[i]]) else: l, r = args ans = st.query(l - 1, r, Vec([0, 0, 0, 0, 0, 1]), Vec([1, 0, 0, 0, 0, 0])) print(ans)