結果
問題 |
No.2879 Range Flip Queries
|
ユーザー |
👑 |
提出日時 | 2025-09-03 22:23:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 847 ms / 2,000 ms |
コード長 | 942 bytes |
コンパイル時間 | 324 ms |
コンパイル使用メモリ | 82,596 KB |
実行使用メモリ | 144,472 KB |
最終ジャッジ日時 | 2025-09-03 22:23:51 |
合計ジャッジ時間 | 23,548 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
# 双対BIT class Dual_Fenwick_Tree: def __init__(self, n): self._n = n self.data = [0] * n # l 以上 r 未満の区間に x を加算する def prod(self, l, r, x): self._add(l, x) if r < self._n: self._add(r, -x) # 添え字 p の値を返す def get(self, p): return self._sum(p + 1) - self._sum(0) def _add(self, p, x): p += 1 while p <= self._n: self.data[p - 1] += x p += p & -p def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] r -= r & -r return s N, Q = map(int, input().split()) A = list(map(int, input().split())) ftree = Dual_Fenwick_Tree(N) for i, a in enumerate(A): ftree.prod(i, i + 1, a) for _ in range(Q): l, r = map(lambda x: int(x) - 1, input().split()) ftree.prod(l, r + 1, 1) print(*[ftree.get(i) % 2 for i in range(N)])