結果

問題 No.2336 Do you like typical problems?
ユーザー PNJ
提出日時 2024-06-12 00:00:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,805 ms / 2,000 ms
コード長 572 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 101,704 KB
最終ジャッジ日時 2024-06-12 00:00:28
合計ジャッジ時間 15,096 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
inv_2 = (mod + 1) // 2

N = int(input())
ans = N*(N-1) // 2
S = []
for i in range(N):
  b,c = map(int,input().split())
  le = c - b + 1
  S.append((b,le))
  S.append((c+1,-le))
S.sort()

s = 0
t = 0
p = 0
for a,le in S:
  res = (s*s - t) % mod
  res = res * inv_2 % mod
  res = res * (a - p) % mod
  ans = (ans - res) % mod
  l = pow(abs(le),mod - 2,mod)
  if le > 0:
    s += l
    t += l * l % mod
  else:
    s -= l
    t -= l * l % mod
  s %= mod
  t %= mod
  p = a
ans *= N*(N-1) // 2
ans %= mod
for n in range(1,N-1):
  ans = ans * n % mod
print(ans)
0