結果

問題 No.2336 Do you like typical problems?
ユーザー titiatitia
提出日時 2023-10-04 05:20:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,968 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 159,916 KB
最終ジャッジ日時 2023-10-04 05:20:37
合計ジャッジ時間 15,028 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
89,940 KB
testcase_01 AC 91 ms
89,804 KB
testcase_02 AC 92 ms
89,916 KB
testcase_03 AC 93 ms
89,936 KB
testcase_04 AC 93 ms
89,940 KB
testcase_05 AC 94 ms
89,984 KB
testcase_06 AC 92 ms
89,776 KB
testcase_07 AC 94 ms
89,904 KB
testcase_08 AC 127 ms
91,704 KB
testcase_09 AC 126 ms
91,688 KB
testcase_10 AC 126 ms
91,656 KB
testcase_11 AC 128 ms
91,348 KB
testcase_12 AC 127 ms
92,044 KB
testcase_13 AC 1,906 ms
159,916 KB
testcase_14 AC 1,968 ms
159,196 KB
testcase_15 AC 1,882 ms
158,796 KB
testcase_16 AC 1,892 ms
159,108 KB
testcase_17 AC 1,931 ms
159,596 KB
testcase_18 AC 517 ms
157,448 KB
testcase_19 AC 497 ms
158,076 KB
testcase_20 AC 1,136 ms
159,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from operator import itemgetter

mod=998244353

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

# 高速ベキ乗
def fast_pow(x,y):
    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)
    
    if com==1:
        now1=(now1+LINV)%mod
        ANS1=(ANS1-LINV)%mod
    else:
        now1=(now1-LINV)%mod

    if i+1<len(Q) and x!=Q[i+1][0]:
        z=Q[i+1][0]

        # [x,z)の間を考え、答えに加算。

        ANS1=(ANS1+now1*now1%mod*(z-x)%mod)%mod


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

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