結果

問題 No.2336 Do you like typical problems?
ユーザー ニックネームニックネーム
提出日時 2023-06-02 23:24:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 818 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 248,300 KB
最終ジャッジ日時 2023-08-28 05:57:05
合計ジャッジ時間 9,841 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,160 KB
testcase_01 AC 69 ms
71,248 KB
testcase_02 AC 71 ms
71,252 KB
testcase_03 AC 70 ms
71,260 KB
testcase_04 AC 71 ms
71,252 KB
testcase_05 AC 70 ms
71,148 KB
testcase_06 AC 70 ms
71,120 KB
testcase_07 AC 70 ms
71,368 KB
testcase_08 AC 128 ms
78,584 KB
testcase_09 AC 125 ms
78,668 KB
testcase_10 AC 127 ms
78,592 KB
testcase_11 AC 123 ms
78,468 KB
testcase_12 AC 125 ms
78,300 KB
testcase_13 AC 889 ms
247,492 KB
testcase_14 AC 916 ms
248,300 KB
testcase_15 AC 909 ms
248,044 KB
testcase_16 AC 906 ms
248,036 KB
testcase_17 AC 907 ms
247,888 KB
testcase_18 AC 431 ms
94,480 KB
testcase_19 AC 439 ms
94,052 KB
testcase_20 AC 818 ms
247,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input()); mod = 998244353
bc = [tuple(map(int,input().split())) for _ in range(n)]
itov = set()
for b,c in bc: itov.add(b); itov.add(c+1)
itov = sorted(itov); m = len(itov)
vtoi = {v:i+1 for i,v in enumerate(itov)}
imos1 = [0]*(m+1); imos2=  [0]*(m+1)
for b,c in bc:
    rev1 = pow(c-b+1,mod-2,mod); rev2 = rev1**2%mod
    imos1[vtoi[b]] += rev1; imos2[vtoi[b]] += rev2
    imos1[vtoi[c+1]] -= rev1; imos2[vtoi[c+1]] -= rev2
for i in range(m):
    imos1[i+1] = sum(imos1[i:i+2])%mod
    imos2[i+1] = sum(imos2[i:i+2])%mod
two = pow(2,mod-2,mod); ans = n*(n-1)//2
for i in range(1,m): ans = (ans-(imos1[i]**2-imos2[i])%mod*two%mod*(itov[i]-itov[i-1]))%mod
for i in range(3,n+1): ans = ans*i%mod
print(ans)
0