結果
問題 | No.2879 Range Flip Queries |
ユーザー |
👑 |
提出日時 | 2024-09-08 14:35:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 944 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 321 ms |
コンパイル使用メモリ | 82,356 KB |
実行使用メモリ | 144,632 KB |
最終ジャッジ日時 | 2024-09-08 14:35:51 |
合計ジャッジ時間 | 21,969 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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)) % 2 def _add(self, p, x): p += 1 while p <= self._n: self.data[p - 1] += x self.data[p - 1] %= 2 p += p & -p def _sum(self, r): s = 0 while r > 0: s += self.data[r - 1] s %= 2 r -= r & -r return s N, Q = map(int, input().split()) A = list(map(int, input().split())) fenwick = Dual_Fenwick_Tree(N) for i in range(N): fenwick.prod(i, i + 1, A[i]) for _ in range(Q): L, R = map(int, input().split()) fenwick.prod(L - 1, R, 1) for i in range(N): print(fenwick.get(i), end=" ")