結果

問題 No.2336 Do you like typical problems?
ユーザー hir355hir355
提出日時 2023-06-03 00:03:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,697 ms / 2,000 ms
コード長 1,134 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 267,716 KB
最終ジャッジ日時 2023-08-28 07:39:58
合計ジャッジ時間 14,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,252 KB
testcase_01 AC 69 ms
71,188 KB
testcase_02 AC 69 ms
71,172 KB
testcase_03 AC 69 ms
71,108 KB
testcase_04 AC 70 ms
71,108 KB
testcase_05 AC 70 ms
71,112 KB
testcase_06 AC 70 ms
71,284 KB
testcase_07 AC 72 ms
71,248 KB
testcase_08 AC 108 ms
78,020 KB
testcase_09 AC 108 ms
77,680 KB
testcase_10 AC 108 ms
77,768 KB
testcase_11 AC 108 ms
77,872 KB
testcase_12 AC 108 ms
77,620 KB
testcase_13 AC 1,697 ms
267,716 KB
testcase_14 AC 1,682 ms
261,788 KB
testcase_15 AC 1,677 ms
261,588 KB
testcase_16 AC 1,672 ms
261,440 KB
testcase_17 AC 1,666 ms
263,216 KB
testcase_18 AC 502 ms
95,044 KB
testcase_19 AC 516 ms
92,684 KB
testcase_20 AC 1,017 ms
267,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
compress = lambda arr: {e: i for i, e in enumerate(sorted(set(arr)))}
compress2 = lambda arr: {i: e for i, e in enumerate(sorted(set(arr)))}
MOD = 998244353
n = int(input())
b = [0] * n
c = [0] * n
l = []
for i in range(n):
    b[i], c[i] = map(int, input().split())
    b[i] -= 1
    l.append(b[i])
    l.append(c[i])
cp = compress(l)
cp2 = compress2(l)
# ans = 0
# for j in range(n):
#     for k in range(j + 1, n):
#         ans += (1 - max(0, min(c[j] - b[j], c[k] - b[k], c[j] - b[k], c[k] - b[j]) + 1) * pow((c[j] - b[j] + 1) * (c[k] - b[k] + 1), MOD - 2, MOD)) * f % MOD

ans = 0
m = len(cp)
x = [0] * m
y = [0] * m
for j in range(n):
    xx = pow(c[j] - b[j], MOD - 2, MOD)
    yy = pow((c[j] - b[j]) ** 2, MOD - 2, MOD)
    x[cp[b[j]]] += xx
    x[cp[c[j]]] -= xx
    y[cp[b[j]]] += yy
    y[cp[c[j]]] -= yy
s = 0
s2 = 0
f = 1
for i in range(n - 2):
    f *= (i + 1)
    f %= MOD
v = pow(2, MOD - 2, MOD)
for j in range(m - 1):
    s += x[j]
    s2 += y[j]
    ans += (s ** 2 - s2) * v * (cp2[j + 1] - cp2[j])
    ans %= MOD
print(((n * (n - 1) // 2 - ans) * n * (n - 1) // 2) * f % MOD)
0