結果
問題 | No.2292 Interval Union Find |
ユーザー | t98slider |
提出日時 | 2023-04-08 15:56:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,256 ms / 5,000 ms |
コード長 | 5,026 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 81,932 KB |
実行使用メモリ | 266,160 KB |
最終ジャッジ日時 | 2024-10-03 11:35:19 |
合計ジャッジ時間 | 48,123 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
54,068 KB |
testcase_01 | AC | 37 ms
55,168 KB |
testcase_02 | AC | 38 ms
54,448 KB |
testcase_03 | AC | 39 ms
53,860 KB |
testcase_04 | AC | 995 ms
140,668 KB |
testcase_05 | AC | 918 ms
143,160 KB |
testcase_06 | AC | 920 ms
140,492 KB |
testcase_07 | AC | 932 ms
146,044 KB |
testcase_08 | AC | 1,256 ms
259,244 KB |
testcase_09 | AC | 1,161 ms
259,032 KB |
testcase_10 | AC | 1,180 ms
259,128 KB |
testcase_11 | AC | 1,189 ms
258,152 KB |
testcase_12 | AC | 1,178 ms
262,900 KB |
testcase_13 | AC | 1,147 ms
244,512 KB |
testcase_14 | AC | 1,172 ms
245,920 KB |
testcase_15 | AC | 1,188 ms
257,288 KB |
testcase_16 | AC | 1,145 ms
245,148 KB |
testcase_17 | AC | 1,210 ms
258,320 KB |
testcase_18 | AC | 609 ms
265,952 KB |
testcase_19 | AC | 739 ms
262,020 KB |
testcase_20 | AC | 738 ms
261,920 KB |
testcase_21 | AC | 1,096 ms
265,216 KB |
testcase_22 | AC | 1,098 ms
264,952 KB |
testcase_23 | AC | 1,145 ms
264,628 KB |
testcase_24 | AC | 1,128 ms
265,140 KB |
testcase_25 | AC | 1,091 ms
265,256 KB |
testcase_26 | AC | 1,114 ms
264,572 KB |
testcase_27 | AC | 1,125 ms
266,160 KB |
testcase_28 | AC | 1,075 ms
265,208 KB |
testcase_29 | AC | 1,110 ms
264,752 KB |
testcase_30 | AC | 1,082 ms
264,596 KB |
testcase_31 | AC | 1,103 ms
265,012 KB |
testcase_32 | AC | 1,053 ms
266,132 KB |
testcase_33 | AC | 1,129 ms
265,652 KB |
testcase_34 | AC | 1,113 ms
264,800 KB |
testcase_35 | AC | 1,131 ms
265,716 KB |
testcase_36 | AC | 1,089 ms
265,444 KB |
testcase_37 | AC | 1,106 ms
265,328 KB |
testcase_38 | AC | 1,132 ms
264,784 KB |
testcase_39 | AC | 1,106 ms
265,260 KB |
testcase_40 | AC | 1,113 ms
264,752 KB |
testcase_41 | AC | 348 ms
121,768 KB |
testcase_42 | AC | 368 ms
121,780 KB |
testcase_43 | AC | 608 ms
125,492 KB |
testcase_44 | AC | 720 ms
124,860 KB |
testcase_45 | AC | 733 ms
125,328 KB |
testcase_46 | AC | 720 ms
125,920 KB |
testcase_47 | AC | 781 ms
125,160 KB |
ソースコード
from sys import stdin 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): 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): 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(l%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 op(lhs, rhs): return lhs & rhs def mapping(f, x): return x if f == -1 else f def composition(f, g): return g if f == -1 else f N, Q = map(int, stdin.readline().split()) query = [[] for _ in range(Q)] compress = [0] for i in range(Q): query[i] = list(map(int, stdin.readline().split())) compress.append(query[i][1]) if len(query[i]) >= 3: compress.append(query[i][2]) compress = sorted(list(set(compress))) d = {compress[i] : i for i in range(len(compress))} uf = lazy_segtree([0] * len(compress), op, 1, mapping, composition, -1) for i in range(Q): typ, u, v = query[i][0], d[query[i][1]], d[query[i][2]] if len(query[i]) >= 3 else 0 if typ <= 2: uf.apply(u, v, 2 - typ) elif typ == 3: if v < u : u, v = v, u print(uf.prod(u, v)) else: l = uf.min_left(u, lambda x : x != 0) r = uf.max_right(u, lambda x : x != 0) print(compress[r] - compress[l] + 1)