結果
問題 | No.2875 What is My Rank? |
ユーザー |
![]() |
提出日時 | 2024-09-06 21:45:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 451 ms / 2,000 ms |
コード長 | 3,199 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 90,280 KB |
最終ジャッジ日時 | 2024-09-06 21:45:47 |
合計ジャッジ時間 | 8,888 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
def Extended_Euclid(n,m):stack=[]while m:stack.append((n,m))n,m=m,n%mif n>=0:x,y=1,0else:x,y=-1,0for i in range(len(stack)-1,-1,-1):n,m=stack[i]x,y=y,x-(n//m)*yreturn x,yclass MOD:def __init__(self,p,e=None):self.p=pself.e=eif self.e==None:self.mod=self.pelse:self.mod=self.p**self.edef Pow(self,a,n):a%=self.modif n>=0:return pow(a,n,self.mod)else:#assert math.gcd(a,self.mod)==1x=Extended_Euclid(a,self.mod)[0]return pow(x,-n,self.mod)def Build_Fact(self,N):assert N>=0self.factorial=[1]if self.e==None:for i in range(1,N+1):self.factorial.append(self.factorial[-1]*i%self.mod)else:self.cnt=[0]*(N+1)for i in range(1,N+1):self.cnt[i]=self.cnt[i-1]ii=iwhile ii%self.p==0:ii//=self.pself.cnt[i]+=1self.factorial.append(self.factorial[-1]*ii%self.mod)self.factorial_inve=[None]*(N+1)self.factorial_inve[-1]=self.Pow(self.factorial[-1],-1)for i in range(N-1,-1,-1):ii=i+1while ii%self.p==0:ii//=self.pself.factorial_inve[i]=(self.factorial_inve[i+1]*ii)%self.moddef Build_Inverse(self,N):self.inverse=[None]*(N+1)assert self.p>Nself.inverse[1]=1for n in range(2,N+1):if n%self.p==0:continuea,b=divmod(self.mod,n)self.inverse[n]=(-a*self.inverse[b])%self.moddef Inverse(self,n):return self.inverse[n]def Fact(self,N):if N<0:return 0retu=self.factorial[N]if self.e!=None and self.cnt[N]:retu*=pow(self.p,self.cnt[N],self.mod)%self.modretu%=self.modreturn retudef Fact_Inve(self,N):if self.e!=None and self.cnt[N]:return Nonereturn self.factorial_inve[N]def Comb(self,N,K,divisible_count=False):if K<0 or K>N:return 0retu=self.factorial[N]*self.factorial_inve[K]%self.mod*self.factorial_inve[N-K]%self.modif self.e!=None:cnt=self.cnt[N]-self.cnt[N-K]-self.cnt[K]if divisible_count:return retu,cntelse:retu*=pow(self.p,cnt,self.mod)retu%=self.modreturn retuN=int(input())L,R=[],[]for i in range(N):l,r=map(int,input().split())l-=1L.append(l)R.append(r)mod=998244353MD=MOD(mod)ans=1for i in range(1,N):if R[0]<=L[i]:p=1elif R[i]<=L[0]:p=0else:c=(R[0]-L[0])*(R[i]-L[i])p=0if R[0]<R[i]:p+=(R[i]-R[0])*(R[0]-L[0])R[i]=R[0]if L[i]<L[0]:L[i]=L[0]p+=(R[i]-L[0]-1+L[i]-L[0])*(R[i]-L[i])//2p*=MD.Pow(c,-1)p%=modans+=pans%=modprint(ans)