結果
| 問題 |
No.2336 Do you like typical problems?
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2023-10-04 05:16:31 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,931 ms / 2,000 ms |
| コード長 | 1,138 bytes |
| コンパイル時間 | 371 ms |
| コンパイル使用メモリ | 82,140 KB |
| 実行使用メモリ | 232,240 KB |
| 最終ジャッジ日時 | 2024-07-26 14:18:17 |
| 合計ジャッジ時間 | 14,161 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from operator import itemgetter
mod=998244353
# 高速ベキ乗
from functools import lru_cache
@lru_cache(maxsize=None)
def fast_pow(x,y,mod):
ANS=1
while y>0:
if y%2==1:
ANS=ANS*x%mod
y-=1
if y>0:
x=x*x%mod
y//=2
return ANS
N=int(input())
LIST=[list(map(int,input().split())) for i in range(N)]
Q=[]
for b,c in LIST:
Q.append((b,c-b+1,1))
Q.append((c+1,c-b+1,2))
Q.sort(key=itemgetter(1))
Q.sort(key=itemgetter(0))
now1=0
ANS1=0
for i in range(len(Q)):
x,length,com=Q[i]
LINV=fast_pow(length,mod-2,mod)
if com==1:
now1+=LINV
ANS1-=LINV
ANS1%=mod
else:
now1-=LINV
now1%=mod
if i+1<len(Q) and x!=Q[i+1][0]:
z=Q[i+1][0]
# [x,z)の間を考え、答えに加算。
ANS1+=now1*now1%mod*(z-x)%mod
ANS1%=mod
ANS2=(N*(N-1)//2-ANS1*fast_pow(2,mod-2,mod))%mod
F=[1]
for i in range(1,200020):
F.append(F[-1]*i%mod)
print(ANS2*F[N]*fast_pow(2,mod-2,mod)%mod)
titia