結果
問題 | No.2930 Larger Mex |
ユーザー | hato336 |
提出日時 | 2024-10-12 15:30:26 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 8,811 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 133,320 KB |
最終ジャッジ日時 | 2024-10-12 15:30:58 |
合計ジャッジ時間 | 31,654 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
95,104 KB |
testcase_01 | AC | 145 ms
88,808 KB |
testcase_02 | AC | 158 ms
94,848 KB |
testcase_03 | AC | 297 ms
96,000 KB |
testcase_04 | AC | 231 ms
95,872 KB |
testcase_05 | AC | 274 ms
96,128 KB |
testcase_06 | AC | 223 ms
96,128 KB |
testcase_07 | AC | 230 ms
96,128 KB |
testcase_08 | AC | 500 ms
131,968 KB |
testcase_09 | AC | 502 ms
128,640 KB |
testcase_10 | AC | 495 ms
132,340 KB |
testcase_11 | AC | 449 ms
125,328 KB |
testcase_12 | AC | 527 ms
132,864 KB |
testcase_13 | AC | 515 ms
132,224 KB |
testcase_14 | AC | 557 ms
132,684 KB |
testcase_15 | AC | 930 ms
128,256 KB |
testcase_16 | AC | 752 ms
125,484 KB |
testcase_17 | AC | 1,008 ms
132,352 KB |
testcase_18 | AC | 900 ms
128,256 KB |
testcase_19 | AC | 696 ms
132,864 KB |
testcase_20 | AC | 743 ms
132,608 KB |
testcase_21 | AC | 849 ms
132,508 KB |
testcase_22 | WA | - |
testcase_23 | AC | 696 ms
128,896 KB |
testcase_24 | AC | 948 ms
131,968 KB |
testcase_25 | WA | - |
testcase_26 | AC | 427 ms
131,584 KB |
testcase_27 | AC | 411 ms
125,184 KB |
testcase_28 | AC | 420 ms
128,256 KB |
testcase_29 | AC | 416 ms
128,000 KB |
testcase_30 | AC | 413 ms
129,300 KB |
testcase_31 | AC | 390 ms
123,264 KB |
testcase_32 | AC | 424 ms
129,408 KB |
testcase_33 | AC | 430 ms
129,792 KB |
testcase_34 | AC | 637 ms
132,352 KB |
testcase_35 | AC | 406 ms
118,272 KB |
testcase_36 | AC | 828 ms
132,332 KB |
testcase_37 | AC | 495 ms
129,024 KB |
testcase_38 | AC | 887 ms
132,504 KB |
testcase_39 | AC | 732 ms
132,572 KB |
testcase_40 | AC | 878 ms
132,380 KB |
testcase_41 | AC | 629 ms
128,896 KB |
testcase_42 | AC | 448 ms
130,640 KB |
testcase_43 | AC | 465 ms
127,340 KB |
testcase_44 | AC | 443 ms
127,352 KB |
testcase_45 | AC | 439 ms
127,616 KB |
testcase_46 | AC | 244 ms
119,524 KB |
testcase_47 | AC | 215 ms
119,552 KB |
testcase_48 | AC | 196 ms
110,212 KB |
testcase_49 | AC | 214 ms
119,552 KB |
testcase_50 | AC | 978 ms
130,616 KB |
testcase_51 | AC | 511 ms
133,248 KB |
testcase_52 | WA | - |
ソースコード
import collections,sys,math,functools,operator,itertools,bisect,heapq,decimal,string,time,random #https://github.com/shakayami/ACL-for-python/blob/master/segtree.py class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<<self.log self.d=[E for i in range(2*self.size)] 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 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 return self.d[p+self.size] def prod(self,l,r): assert 0<=l and l<=r and r<=self.n sml=self.e smr=self.e l+=self.size r+=self.size while(l<r): if (l&1): sml=self.op(sml,self.d[l]) l+=1 if (r&1): smr=self.op(self.d[r-1],smr) r-=1 l>>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def max_right(self,l,f): assert 0<=l and l<=self.n assert f(self.e) if l==self.n: return self.n l+=self.size sm=self.e while(1): while(l%2==0): l>>=1 if not(f(self.op(sm,self.d[l]))): while(l<self.size): l=2*l if f(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,f): assert 0<=r and r<=self.n assert f(self.e) if r==0: return 0 r+=self.size sm=self.e while(1): r-=1 while(r>1 and (r%2)): r>>=1 if not(f(self.op(self.d[r],sm))): while(r<self.size): r=(2*r+1) if f(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 update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) #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): 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 mod = 998244353 #区間加算・区間最小値取得 lst = lazy_segtree([],min,10**18,operator.add,operator.add,0) #区間加算・区間最大値取得 lst = lazy_segtree([],max,-10**18,operator.add,operator.add,0) #区間加算・区間和取得 lst = lazy_segtree([(alist[i],1) for i in range(n)],lambda x,y:((x[0]+y[0])%mod,x[1]+y[1]),(0,0),lambda x,y:((y[0]+x*y[1])%mod,y[1]),operator.add,0) #区間変更・区間最小値取得 lst = lazy_segtree([],min,10**18,lambda x,y:y if x == 10**18 else x,lambda x,y:y if x == 10**18 else x,10**18) #区間変更・区間最大値取得 lst = lazy_segtree([],max,-10**18,lambda x,y:y if x == -10**18 else x,lambda x,y:y if x == -10**18 else x,-10**18) #区間変更・区間和取得 lst = lazy_segtree([(alist[i],1) for i in range(n)],lambda x,y:((x[0]+y[0])%mod,x[1]+y[1]),(0,0),lambda x,y:(y[1]*x,y[1]) if x != 10**18 else y,lambda x,y:y if x == 10**18 else x,10**18) def op(x,y): return #xはlazy, yはd def mapping(x,y): return #yが作用してからxが作用する def composition(x,y): return #sys.setrecursionlimit(10**9) #sys.set_int_max_str_digits(0) #input = sys.stdin.readline n,m = map(int,input().split()) a = list(map(int,input().split())) if m == 0: for i in range(n): print(n-i) exit() #https://github.com/tsutaj/pastbook-2-source-code/blob/main/python/chapter3/3-2-1.py l, r = 0, 0 prod = 1 ans = 0 st = segtree([0 for i in range(2*10**5+1)],min,10**18) lst = lst = lazy_segtree([0 for i in range(n+1)],min,10**18,operator.add,operator.add,0) for l in range(n): while r < n: st.set(a[r],st.get(a[r])+1) if st.prod(0,m) == 1: st.set(a[r],st.get(a[r])-1) break r += 1 z = r-l+1 zz = n-l+1 #print(l,z,zz) if z != n and z <= zz: lst.apply(z,zz,1) if r - l >= 1: st.set(a[l],st.get(a[l])-1) else: r += 1 for i in range(1,n+1): print(lst.get(i))