結果
問題 | No.318 学学学学学 |
ユーザー | BB_Fe3 |
提出日時 | 2022-09-12 17:53:10 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,181 bytes |
コンパイル時間 | 385 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 198,668 KB |
最終ジャッジ日時 | 2024-05-07 04:32:33 |
合計ジャッジ時間 | 8,427 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | -- | - |
testcase_02 | -- | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
ソースコード
def seg_func(x,y): return x+y def composition(m,n): if n == None: return m else: return n def mapping(x,m): if m == None: return x else: return [m]*len(x) seg_id = [] op_id = None class LazySegTree(): def __init__(self,val,seg_func=seg_func,composition=composition,mapping=mapping,seg_id=seg_id,op_id=op_id): self.len = len(val) self.seg_func = seg_func self.composition = composition self.mapping = mapping self.seg_id = seg_id self.op_id = op_id self.num = 2**((self.len-1).bit_length()) self.tree = [self.seg_id for _ in range(2*self.num)] self.lazy = [self.op_id for _ in range(2*self.num)] for i in range(self.len): self.tree[self.num+i] = val[i] for i in range(self.num-1,0,-1): self.tree[i] = self.seg_func(self.tree[2*i],self.tree[2*i+1]) def gindex(self,l,r): l += self.num r += self.num lm = l>>(l&-l).bit_length() rm = r>>(r&-r).bit_length() while r>l: if r<=rm: yield r if l<=lm: yield l r >>= 1 l >>= 1 while l: yield l l >>= 1 def propagates(self,*ids): for i in reversed(ids): m = self.lazy[i] if m == self.op_id: continue self.lazy[i] = self.op_id self.lazy[2*i] = self.composition(self.lazy[2*i],m) self.lazy[2*i+1] = self.composition(self.lazy[2*i+1],m) self.tree[2*i] = self.mapping(self.tree[2*i],m) self.tree[2*i+1] = self.mapping(self.tree[2*i+1],m) def update(self,l,r,m): assert 0 <= l and l < r and r <= self.len ids = self.gindex(l,r) self.propagates(*self.gindex(l,r)) l += self.num r += self.num while l<r: if l&1: self.tree[l] = self.mapping(self.tree[l],m) self.lazy[l] = self.composition(self.lazy[l],m) l += 1 if r&1: self.tree[r-1] = self.mapping(self.tree[r-1],m) self.lazy[r-1] = self.composition(self.lazy[r-1],m) l >>= 1 r >>= 1 for i in ids: self.tree[i] = self.seg_func(self.tree[2*i],self.tree[2*i+1]) def query(self,l,r): assert 0 <= l and l < r and r <= self.len self.propagates(*self.gindex(l,r)) l += self.num r += self.num res1 = self.seg_id res2 = self.seg_id while l<r: if l&1: res1 = self.seg_func(res1,self.tree[l]) l += 1 if r&1: res2 = self.seg_func(self.tree[r-1],res2) l >>= 1 r >>= 1 return self.seg_func(res1,res2) n=int(input()) A=list(map(int,input().split())) A_sorted=sorted(set(A)) A=[[a] for a in map(str,A)] A_sorted=list(map(str,A_sorted)) s=LazySegTree([[''] for _ in range(n)]) for a in A_sorted: l=A.index([a]) r=n-A[::-1].index([a]) s.update(l,r,a) print(' '.join(s.tree[1]))