結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー |
![]() |
提出日時 | 2020-04-25 12:00:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,316 ms / 5,000 ms |
コード長 | 3,164 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 191,280 KB |
最終ジャッジ日時 | 2024-11-06 22:02:53 |
合計ジャッジ時間 | 14,453 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
import sysread = sys.stdin.buffer.readreadline = sys.stdin.buffer.readlinereadlines = sys.stdin.buffer.readlinesclass LazySegTree:X_unit = (0, 0, 0) # 無色、色1、色2A_unit = 0@classmethoddef X_f(cls, x, y):a, b, c = xd, e, f = yreturn (a + d, b + e, c + f)@classmethoddef A_f(cls, x, y):if not y:return xreturn y@classmethoddef operate(cls, x, y):if not y:return xs = sum(x)if y == 1:return (0, s, 0)else:return (0, 0, s)def __init__(self, N):self.N = Nself.X = [self.X_unit] * (N + N)self.A = [self.A_unit] * (N + N)def build(self, seq):for i, x in enumerate(seq, self.N):self.X[i] = xfor i in range(self.N - 1, 0, -1):self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])def _eval_at(self, i):return self.operate(self.X[i], self.A[i])def _propagate_at(self, i):self.X[i] = self._eval_at(i)self.A[i << 1] = self.A_f(self.A[i << 1], self.A[i])self.A[i << 1 | 1] = self.A_f(self.A[i << 1 | 1], self.A[i])self.A[i] = self.A_unitdef _propagate_above(self, i):H = i.bit_length() - 1for h in range(H, 0, -1):self._propagate_at(i >> h)def _recalc_above(self, i):while i > 1:i >>= 1self.X[i] = self.X_f(self._eval_at(i << 1), self._eval_at(i << 1 | 1))def set_val(self, i, x):i += self.Nself._propagate_above(i)self.X[i] = xself.A[i] = self.A_unitself._recalc_above(i)def fold(self, L, R):L += self.NR += self.Nself._propagate_above(L // (L & -L))self._propagate_above(R // (R & -R) - 1)vL = self.X_unitvR = self.X_unitwhile L < R:if L & 1:vL = self.X_f(vL, self._eval_at(L))L += 1if R & 1:R -= 1vR = self.X_f(self._eval_at(R), vR)L >>= 1R >>= 1return self.X_f(vL, vR)def operate_range(self, L, R, x):L += self.NR += self.NL0 = L // (L & -L)R0 = R // (R & -R) - 1self._propagate_above(L0)self._propagate_above(R0)while L < R:if L & 1:self.A[L] = self.A_f(self.A[L], x)L += 1if R & 1:R -= 1self.A[R] = self.A_f(self.A[R], x)L >>= 1R >>= 1self._recalc_above(L0)self._recalc_above(R0)N = int(readline())Q = int(readline())score_A = 0score_B = 0seg = LazySegTree(N)seg.build([(1, 0, 0)] * N)m = map(int, read().split())for x, L, R in zip(m, m, m):R += 1if x == 0:_, a, b = seg.fold(L, R)if a > b:score_A += aelif b > a:score_B += belse:seg.operate_range(L, R, x)_, a, b = seg.fold(0, N)print(score_A + a, score_B + b)