結果
問題 | No.230 Splarraay スプラレェーイ |
ユーザー | 山本信二 |
提出日時 | 2022-04-05 11:59:46 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,729 bytes |
コンパイル時間 | 116 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 27,648 KB |
最終ジャッジ日時 | 2024-11-26 12:21:42 |
合計ジャッジ時間 | 30,306 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
11,008 KB |
testcase_01 | AC | 27 ms
10,880 KB |
testcase_02 | AC | 27 ms
11,008 KB |
testcase_03 | AC | 27 ms
11,136 KB |
testcase_04 | AC | 27 ms
11,008 KB |
testcase_05 | AC | 47 ms
11,136 KB |
testcase_06 | AC | 249 ms
11,520 KB |
testcase_07 | AC | 44 ms
11,136 KB |
testcase_08 | AC | 62 ms
11,008 KB |
testcase_09 | AC | 2,310 ms
18,048 KB |
testcase_10 | AC | 1,201 ms
11,008 KB |
testcase_11 | AC | 1,411 ms
15,232 KB |
testcase_12 | AC | 2,309 ms
18,048 KB |
testcase_13 | AC | 361 ms
12,032 KB |
testcase_14 | AC | 1,244 ms
15,232 KB |
testcase_15 | AC | 3,631 ms
15,232 KB |
testcase_16 | AC | 4,346 ms
20,352 KB |
testcase_17 | TLE | - |
testcase_18 | AC | 2,944 ms
27,648 KB |
testcase_19 | AC | 3,440 ms
24,320 KB |
ソースコード
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)