結果
問題 | No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-10-15 00:00:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,796 ms / 6,000 ms |
コード長 | 3,493 bytes |
コンパイル時間 | 180 ms |
コンパイル使用メモリ | 82,476 KB |
実行使用メモリ | 210,108 KB |
最終ジャッジ日時 | 2024-06-26 18:14:45 |
合計ジャッジ時間 | 110,560 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,608 KB |
testcase_01 | AC | 36 ms
52,608 KB |
testcase_02 | AC | 36 ms
52,736 KB |
testcase_03 | AC | 1,754 ms
155,588 KB |
testcase_04 | AC | 2,501 ms
181,336 KB |
testcase_05 | AC | 1,576 ms
142,188 KB |
testcase_06 | AC | 2,336 ms
169,048 KB |
testcase_07 | AC | 2,708 ms
180,340 KB |
testcase_08 | AC | 2,631 ms
174,904 KB |
testcase_09 | AC | 1,396 ms
134,612 KB |
testcase_10 | AC | 1,193 ms
136,320 KB |
testcase_11 | AC | 1,813 ms
157,168 KB |
testcase_12 | AC | 1,863 ms
150,044 KB |
testcase_13 | AC | 1,328 ms
142,536 KB |
testcase_14 | AC | 1,104 ms
127,232 KB |
testcase_15 | AC | 3,010 ms
191,440 KB |
testcase_16 | AC | 2,524 ms
180,704 KB |
testcase_17 | AC | 875 ms
118,300 KB |
testcase_18 | AC | 3,527 ms
209,580 KB |
testcase_19 | AC | 3,544 ms
208,560 KB |
testcase_20 | AC | 3,592 ms
209,652 KB |
testcase_21 | AC | 3,601 ms
209,564 KB |
testcase_22 | AC | 3,620 ms
209,832 KB |
testcase_23 | AC | 3,556 ms
208,168 KB |
testcase_24 | AC | 3,702 ms
209,448 KB |
testcase_25 | AC | 3,796 ms
208,216 KB |
testcase_26 | AC | 3,628 ms
209,068 KB |
testcase_27 | AC | 3,585 ms
208,300 KB |
testcase_28 | AC | 3,591 ms
209,184 KB |
testcase_29 | AC | 3,553 ms
209,376 KB |
testcase_30 | AC | 3,584 ms
208,760 KB |
testcase_31 | AC | 3,621 ms
209,844 KB |
testcase_32 | AC | 3,517 ms
208,104 KB |
testcase_33 | AC | 3,379 ms
208,896 KB |
testcase_34 | AC | 3,409 ms
209,848 KB |
testcase_35 | AC | 3,348 ms
209,036 KB |
testcase_36 | AC | 3,320 ms
208,756 KB |
testcase_37 | AC | 3,340 ms
210,108 KB |
testcase_38 | AC | 388 ms
130,928 KB |
testcase_39 | AC | 1,166 ms
134,180 KB |
testcase_40 | AC | 1,150 ms
208,912 KB |
testcase_41 | AC | 36 ms
52,736 KB |
ソースコード
class SegTree: """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """ def __init__(self,size,func,sta): self.n = size self.size = 1 << size.bit_length() self.func = func self.sta = sta self.tree = [sta]*(2*self.size) def build(self, list): """ set list and update tree""" for i,x in enumerate(list,self.size): self.tree[i] = x for i in range(self.size-1,0,-1): self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1]) def set(self,i,x): i += self.size self.tree[i] = x while i > 1: i >>= 1 self.tree[i] = self.func(self.tree[i<<1],self.tree[i<<1 | 1]) def get(self,l,r): """ take the value of [l r) with func (min or max)""" l += self.size r += self.size res = self.sta while l < r: if l & 1: res = self.func(self.tree[l],res) l += 1 if r & 1: res = self.func(self.tree[r-1],res) l >>= 1 r >>= 1 return res def max_right(self, l, x): """[l,r) が ok であるような最大の r を返す""" if l == self.n: return l l += self.size res = self.sta check = True while check or (l & -l) != l: check = False while l%2 == 0: l >>= 1 if not self.func(res,self.tree[l]) < x: while l < self.size: l <<= 1 if self.func(res,self.tree[l]) < x: res = self.func(res,self.tree[l]) l += 1 return l - self.size res = self.func(res,self.tree[l]) l += 1 return self.n def min_left(self, r, x): """(r が ok であるような最小の r を返す probably wrong""" if r == 0: return 0 r += self.size res = self.sta check = True while check and (r & -r) != r: check = False r -= 1 while (r > 1 and r%2): r >>= 1 if not self.func(res, self.tree[r]) < x: while r < self.size: r = 2*r + 1 if self.func(res, self.tree[r]) < x: res = self.func(res, self.tree[r]) r -= 1 return r + 1 - self.size res = self.func(self.tree[r],res) return 0 def func(x,y): return x+y n = int(input()) AT = [list(map(int,input().split())) for i in range(n)] A = [a for a,t in AT] q = int(input()) DLR = [list(map(int,input().split())) for i in range(q)] ans = [0]*q event = [] for i,(a,t) in enumerate(AT): if a == 0: continue event.append([t,-1,i,0]) event.append([t+a,-2,i,0]) for i,(d,l,r) in enumerate(DLR): event.append([d,i,l,r]) seg1 = SegTree(n,func,0) seg3 = SegTree(n,func,0) seg4 = SegTree(n,func,0) seg1.build([a for a,t in AT]) event.sort() for day,ind,x,y in event: if ind == -1: seg3.set(x,1) seg4.set(x,day) elif ind == -2: seg1.set(x,0) seg3.set(x,0) seg4.set(x,0) else: l,r = x-1,y count = seg1.get(l,r) -seg3.get(l,r)*(day+1) + seg4.get(l,r) ans[ind] = count for i in ans: print(i)