結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | hagebooi |
提出日時 | 2019-03-01 18:23:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,520 ms / 5,000 ms |
コード長 | 2,813 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 129,596 KB |
最終ジャッジ日時 | 2024-06-23 12:09:48 |
合計ジャッジ時間 | 11,269 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,992 KB |
testcase_01 | AC | 38 ms
52,956 KB |
testcase_02 | AC | 40 ms
52,736 KB |
testcase_03 | AC | 37 ms
52,352 KB |
testcase_04 | AC | 36 ms
52,736 KB |
testcase_05 | AC | 126 ms
77,164 KB |
testcase_06 | AC | 216 ms
78,336 KB |
testcase_07 | AC | 108 ms
76,212 KB |
testcase_08 | AC | 211 ms
78,816 KB |
testcase_09 | AC | 687 ms
98,840 KB |
testcase_10 | AC | 523 ms
78,628 KB |
testcase_11 | AC | 433 ms
88,780 KB |
testcase_12 | AC | 739 ms
99,580 KB |
testcase_13 | AC | 208 ms
79,488 KB |
testcase_14 | AC | 310 ms
81,568 KB |
testcase_15 | AC | 987 ms
85,672 KB |
testcase_16 | AC | 1,218 ms
108,536 KB |
testcase_17 | AC | 1,520 ms
129,596 KB |
testcase_18 | AC | 821 ms
89,864 KB |
testcase_19 | AC | 918 ms
111,220 KB |
ソースコード
""" f(a, b) = max(a, b) g(a, c) = c(ただしc = 0ならばa) g = h f(a, b) """ class segtree: def __init__(self, n, L = None): self.raw_len = n self.list = L self.init() def init(self): N = 1 n = self.raw_len while N < n: N *= 2 self.len = N self.node = [(0, 0)]*(2*N-1) #fのunityに初期化 self.lazy = [0]*(2*N-1) #gのunityに初期化 if self.list: for i in range(self.raw_len): self.node[i+self.len-1] = self.list[i] for i in range(self.len - 2, -1, -1): self.node[i] = (self.node[2*i+1][0] + self.node[2*i+2][0], self.node[2*i+1][1] + self.node[2*i+2][1]) #f def update(self, i, x):#点更新 i += self.len - 1 self.node[i] = x while i > 0: i = (i-1)//2 self.node[i] = (self.node[2*i+1][0] + self.node[2*i+2][0], self.node[2*i+1][1] + self.node[2*i+2][1]) def eval(self, k, l ,r): if self.lazy[k] != 0: self.node[k] = (self.lazy[k][0] * (r-l), self.lazy[k][1] * (r-l)) #g if k < self.len - 1: self.lazy[2*k+1] = self.lazy[k] self.lazy[2*k+2] = self.lazy[k] self.lazy[k] = 0 #gのunity def range_update(self, a, b, x, k=0, l=0, r=None): if r == None: r = self.len self.eval(k, l, r) if r <= a or b <= l: return 0 if a <= l and r <= b: self.lazy[k] = x self.eval(k, l, r) else: self.range_update(a, b, x, k*2+1, l, (l+r)//2) self.range_update(a, b, x, k*2+2, (l+r)//2, r) self.node[k] = (self.node[2*k+1][0] + self.node[2*k+2][0], self.node[2*k+1][1] + self.node[2*k+2][1]) #f def query(self, a, b, k = 0, l = 0, r = None): if r == None: r = self.len if r <= a or b <= l: return (0, 0) #fのunity self.eval(k, l, r) if a <= l and r <= b: return self.node[k] else: vl = self.query(a, b, k*2+1, l, (l+r)//2) vr = self.query(a, b, k*2+2, (l+r)//2, r) return (vl[0] + vr[0], vl[1] + vr[1]) def nodes(self): for i in range(2*self.len-1): self.eval(i) res = self.node[self.len-1:] return list(res) N = int(input()) Q = int(input()) seg = segtree(N) a_s = b_s = 0 for _ in range(Q): x, l, r = (int(i) for i in input().split()) if x == 0: a, b = seg.query(l, r+1) if a > b: a_s += a elif a < b: b_s += b elif x == 1: seg.range_update(l, r+1, (1, 0)) else: seg.range_update(l, r+1, (0, 1)) a, b = seg.query(0, N) a_s += a b_s += b print(a_s, b_s)