結果

問題 No.2336 Do you like typical problems?
ユーザー titia
提出日時 2023-10-04 05:07:30
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 875 bytes
コンパイル時間 339 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 166,172 KB
最終ジャッジ日時 2024-07-26 14:17:10
合計ジャッジ時間 17,186 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from operator import itemgetter

mod=998244353

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]
    
    if com==1:
        now1+=pow(length,mod-2,mod)
    else:
        now1-=pow(length,mod-2,mod)

    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
        #print("!",now1)
        ANS1%=mod

for b,c in LIST:
    k=c-b+1

    ANS1-=pow(k,-1,mod)
    ANS1%=mod


ANS2=(N*(N-1)//2-ANS1*pow(2,-1,mod))%mod


F=[1]
for i in range(1,200020):
    F.append(F[-1]*i%mod)


print(ANS2*F[N]*pow(2,mod-2,mod)%mod)


0