結果
問題 | No.1675 Strange Minimum Query |
ユーザー | ygd. |
提出日時 | 2021-09-12 13:04:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,788 ms / 2,000 ms |
コード長 | 6,581 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,444 KB |
実行使用メモリ | 191,536 KB |
最終ジャッジ日時 | 2024-06-24 01:29:33 |
合計ジャッジ時間 | 38,851 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,448 KB |
testcase_01 | AC | 45 ms
56,092 KB |
testcase_02 | AC | 43 ms
56,284 KB |
testcase_03 | AC | 1,161 ms
132,524 KB |
testcase_04 | AC | 1,185 ms
145,168 KB |
testcase_05 | AC | 338 ms
91,908 KB |
testcase_06 | AC | 1,365 ms
145,168 KB |
testcase_07 | AC | 1,538 ms
166,932 KB |
testcase_08 | AC | 63 ms
69,516 KB |
testcase_09 | AC | 138 ms
78,344 KB |
testcase_10 | AC | 817 ms
139,252 KB |
testcase_11 | AC | 384 ms
98,280 KB |
testcase_12 | AC | 884 ms
143,144 KB |
testcase_13 | AC | 742 ms
135,892 KB |
testcase_14 | AC | 1,097 ms
191,536 KB |
testcase_15 | AC | 933 ms
189,084 KB |
testcase_16 | AC | 46 ms
56,932 KB |
testcase_17 | AC | 432 ms
94,424 KB |
testcase_18 | AC | 528 ms
99,728 KB |
testcase_19 | AC | 656 ms
115,800 KB |
testcase_20 | AC | 1,182 ms
152,556 KB |
testcase_21 | AC | 1,071 ms
145,408 KB |
testcase_22 | AC | 1,359 ms
166,864 KB |
testcase_23 | AC | 1,073 ms
128,768 KB |
testcase_24 | AC | 996 ms
136,408 KB |
testcase_25 | AC | 761 ms
112,764 KB |
testcase_26 | AC | 502 ms
101,944 KB |
testcase_27 | AC | 994 ms
141,048 KB |
testcase_28 | AC | 623 ms
114,088 KB |
testcase_29 | AC | 519 ms
106,696 KB |
testcase_30 | AC | 497 ms
100,948 KB |
testcase_31 | AC | 1,335 ms
150,888 KB |
testcase_32 | AC | 1,770 ms
189,840 KB |
testcase_33 | AC | 1,788 ms
190,816 KB |
testcase_34 | AC | 1,788 ms
189,936 KB |
testcase_35 | AC | 1,691 ms
182,512 KB |
testcase_36 | AC | 1,673 ms
181,512 KB |
ソースコード
import sys input = sys.stdin.readline from collections import defaultdict # ACL for pythonより # https://github.com/shakayami/ACL-for-python/blob/master/lazysegtree.py class lazy_segtree(): def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def all_apply(self,k,f): self.d[k]=self.mapping(f,self.d[k]) if (k<self.size):self.lz[k]=self.composition(f,self.lz[k]) def push(self,k): self.all_apply(2*k,self.lz[k]) self.all_apply(2*k+1,self.lz[k]) self.lz[k]=self.identity def __init__(self,V,OP,E,MAPPING,COMPOSITION,ID): self.n=len(V) self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] self.lz=[ID for i in range(self.size)] self.e=E self.op=OP self.mapping=MAPPING self.composition=COMPOSITION self.identity=ID for i in range(self.n):self.d[self.size+i]=V[i] for i in range(self.size-1,0,-1):self.update(i) def set(self,p,x): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) self.d[p]=x for i in range(1,self.log+1):self.update(p>>i) def get(self,p): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) return self.d[p] def prod(self,l,r): #[l,r)の取得, [x,x)と取得すると単位元を返すので注意。 assert 0<=l and l<=r and r<=self.n if l==r:return self.e l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<<i)!=l):self.push(l>>i) if (((r>>i)<<i)!=r):self.push(r>>i) sml,smr=self.e,self.e while(l<r): if l&1: sml=self.op(sml,self.d[l]) l+=1 if r&1: r-=1 smr=self.op(self.d[r],smr) l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self):return self.d[1] def apply_point(self,p,f): assert 0<=p and p<self.n p+=self.size for i in range(self.log,0,-1):self.push(p>>i) self.d[p]=self.mapping(f,self.d[p]) for i in range(1,self.log+1):self.update(p>>i) def apply(self,l,r,f): #[l,r)に作用 assert 0<=l and l<=r and r<=self.n if l==r:return l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<<i)!=l):self.push(l>>i) if (((r>>i)<<i)!=r):self.push((r-1)>>i) l2,r2=l,r while(l<r): if (l&1): self.all_apply(l,f) l+=1 if (r&1): r-=1 self.all_apply(r,f) l>>=1 r>>=1 l,r=l2,r2 for i in range(1,self.log+1): if (((l>>i)<<i)!=l):self.update(l>>i) if (((r>>i)<<i)!=r):self.update((r-1)>>i) def max_right(self,l,g): assert 0<=l and l<=self.n assert g(self.e) if l==self.n:return self.n l+=self.size for i in range(self.log,0,-1):self.push(l>>i) sm=self.e while(1): while(i%2==0):l>>=1 if not(g(self.op(sm,self.d[l]))): while(l<self.size): self.push(l) l=(2*l) if (g(self.op(sm,self.d[l]))): sm=self.op(sm,self.d[l]) l+=1 return l-self.size sm=self.op(sm,self.d[l]) l+=1 if (l&-l)==l:break return self.n def min_left(self,r,g): assert (0<=r and r<=self.n) assert g(self.e) if r==0:return 0 r+=self.size for i in range(self.log,0,-1):self.push((r-1)>>i) sm=self.e while(1): r-=1 while(r>1 and (r%2)):r>>=1 if not(g(self.op(self.d[r],sm))): while(r<self.size): self.push(r) r=(2*r+1) if g(self.op(self.d[r],sm)): sm=self.op(self.d[r],sm) r-=1 return r+1-self.size sm=self.op(self.d[r],sm) if (r&-r)==r:break return 0 def operate(x,y): return min(x,y) def mapping(f,x): #LAZYの部分に(x,y)という値を保存する。ただ足すだけならx=1でyを足すということか。 return f[0]*x+f[1] def composition(f,g): return (f[0]*g[0],g[1]*f[0]+f[1]) class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_length() tree = [unit] * (2 * n) for i, v in enumerate(A): tree[i + n] = v for i in range(n - 1, 0, -1): tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) self._n = n self._tree = tree self._dot = dot self._unit = unit def __getitem__(self, i): return self._tree[i + self._n] def update(self, i, v): i += self._n self._tree[i] = v while i != 1: i >>= 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) def add(self, i, v): self.update(i, self[i] + v) def sum(self, l, r): #これで[l,r)から取り出す。 l += self._n r += self._n l_val = r_val = self._unit while l < r: if l & 1: l_val = self._dot(l_val, self._tree[l]) l += 1 if r & 1: r -= 1 r_val = self._dot(self._tree[r], r_val) l >>= 1 r >>= 1 return self._dot(l_val, r_val) def main(): N,Q = map(int,input().split()); INF = pow(10,9) L = defaultdict(list) R = defaultdict(list) comp = set([]) query = [] for i in range(Q): l,r,b = map(int,input().split()) l -= 1; r -= 1 L[l].append(b) R[r].append(b) comp.add(b) query.append((l,r,b)) query.sort(key = lambda x:x[2]) G = lazy_segtree([INF for i in range(N)],operate,INF,mapping,composition,(1,0)) for l,r,b in query: G.apply(l,r+1,(0,b)) ans = [INF]*N for i in range(N): ans[i] = G.get(i) #print(*ans) Tree = SegmentTree(ans,min,INF) for l,r,b in query: mx = Tree.sum(l,r+1) if mx != b: print(-1) break else: print(*ans) if __name__ == '__main__': main()