結果
問題 | No.2950 Max Min Product |
ユーザー | sasa8uyauya |
提出日時 | 2024-10-26 10:37:53 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,964 ms / 3,000 ms |
コード長 | 2,577 bytes |
コンパイル時間 | 647 ms |
コンパイル使用メモリ | 82,440 KB |
実行使用メモリ | 241,968 KB |
最終ジャッジ日時 | 2024-10-26 10:39:23 |
合計ジャッジ時間 | 82,785 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
53,992 KB |
testcase_01 | AC | 34 ms
53,628 KB |
testcase_02 | AC | 36 ms
54,236 KB |
testcase_03 | AC | 1,710 ms
181,720 KB |
testcase_04 | AC | 1,742 ms
190,792 KB |
testcase_05 | AC | 1,629 ms
183,668 KB |
testcase_06 | AC | 2,184 ms
231,284 KB |
testcase_07 | AC | 2,276 ms
231,080 KB |
testcase_08 | AC | 2,421 ms
231,144 KB |
testcase_09 | AC | 1,238 ms
155,256 KB |
testcase_10 | AC | 2,057 ms
209,608 KB |
testcase_11 | AC | 1,717 ms
198,208 KB |
testcase_12 | AC | 2,281 ms
239,984 KB |
testcase_13 | AC | 2,291 ms
239,176 KB |
testcase_14 | AC | 2,319 ms
239,852 KB |
testcase_15 | AC | 2,366 ms
228,964 KB |
testcase_16 | AC | 1,803 ms
177,000 KB |
testcase_17 | AC | 1,993 ms
192,312 KB |
testcase_18 | AC | 2,554 ms
239,240 KB |
testcase_19 | AC | 2,494 ms
239,528 KB |
testcase_20 | AC | 2,527 ms
239,384 KB |
testcase_21 | AC | 1,515 ms
167,576 KB |
testcase_22 | AC | 1,914 ms
197,408 KB |
testcase_23 | AC | 1,361 ms
154,068 KB |
testcase_24 | AC | 2,483 ms
241,968 KB |
testcase_25 | AC | 2,482 ms
241,896 KB |
testcase_26 | AC | 2,466 ms
241,572 KB |
testcase_27 | AC | 2,079 ms
178,216 KB |
testcase_28 | AC | 2,924 ms
227,080 KB |
testcase_29 | AC | 2,152 ms
185,328 KB |
testcase_30 | AC | 2,964 ms
237,892 KB |
testcase_31 | AC | 2,932 ms
234,784 KB |
testcase_32 | AC | 2,925 ms
235,036 KB |
testcase_33 | AC | 2,092 ms
188,296 KB |
testcase_34 | AC | 1,440 ms
149,836 KB |
testcase_35 | AC | 2,135 ms
185,520 KB |
testcase_36 | AC | 2,817 ms
234,708 KB |
testcase_37 | AC | 2,759 ms
234,740 KB |
testcase_38 | AC | 2,738 ms
235,052 KB |
testcase_39 | AC | 35 ms
53,568 KB |
ソースコード
M=998244353 class LazySegTree: def __init__(self,n): self.tl=1 while self.tl<n: self.tl*=2 self.st=[0]*self.tl+[1]*self.tl for i in reversed(range(1,self.tl)): self.st[i]=self.op(self.st[i*2],self.st[i*2+1]) self.lt=[1]*self.tl*2 return def op(self,x,y): return (x+y)%M def mp(self,f,x): return f*x%M def cp(self,g,f): return g*f%M def update(self,y,c): self.st[y]=self.mp(c,self.st[y]) self.lt[y]=self.cp(c,self.lt[y]) return def gindex(self,l,r): l+=self.tl r+=self.tl p=[] while l<=r: if l%2==1: yield l l+=1 if r%2==0: yield r r-=1 l//=2 r//=2 return p def propa(self,l,r): l+=self.tl r+=self.tl while l>0: if l%2==1: break l//=2 while r>0: if r%2==0: break r//=2 p=[] while l>0: p+=[l] l//=2 while r>0: p+=[r] r//=2 while len(p)>0: y=p.pop() if y*2<self.tl*2: self.update(y*2,self.lt[y]) self.update(y*2+1,self.lt[y]) self.lt[y]=1 return def apply(self,l,r,x): self.propa(l,r) for y in self.gindex(l,r): self.update(y,x) l+=self.tl r+=self.tl while l>0: if l%2==1: break l//=2 while r>0: if r%2==0: break r//=2 l//=2 r//=2 while l>0: self.st[l]=self.op(self.st[l*2],self.st[l*2+1]) l//=2 while r>0: self.st[r]=self.op(self.st[r*2],self.st[r*2+1]) r//=2 return def prod(self,l,r): self.propa(l,r) a=0 for i in self.gindex(l,r): a=self.op(a,self.st[i]) return a n=int(input()) a=list(map(int,input().split()))+[0] w=[[0,0] for i in range(n)] p=[[] for i in range(n+1)] X=10**10 a[-1]=X q=[-1] for i in range(n): while (a[q[-1]],q[-1])<(a[i],i): q.pop() w[i][0]=q[-1]+1 q+=[i] q=[n] for i in reversed(range(n)): while (a[q[-1]],q[-1])<(a[i],i): q.pop() w[i][1]=q[-1]-1 q+=[i] for i in range(n): v=a[i] l,r=w[i] p[i]+=[(l,i,v)] p[r+1]+=[(l,i,pow(v,M-2,M))] a[-1]=-X q=[-1] for i in range(n): while (a[q[-1]],q[-1])>(a[i],i): q.pop() w[i][0]=q[-1]+1 q+=[i] q=[n] for i in reversed(range(n)): while (a[q[-1]],q[-1])>(a[i],i): q.pop() w[i][1]=q[-1]-1 q+=[i] for i in range(n): v=a[i] l,r=w[i] p[i]+=[(l,i,v)] p[r+1]+=[(l,i,pow(v,M-2,M))] ans=0 st=LazySegTree(n) for y in range(n): for l,r,v in p[y]: st.apply(l,r,v) l=0 r=y ans+=st.prod(l,r) ans%=M print(ans)