結果

問題 No.2875 What is My Rank?
ユーザー rlangevinrlangevin
提出日時 2024-09-06 22:59:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 726 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 80,364 KB
最終ジャッジ日時 2024-09-06 22:59:13
合計ジャッジ時間 9,533 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
L, R = [0] * N, [0] * N
inv = 1
mod = 998244353
for i in range(N):
    L[i], R[i] = map(int, input().split())
    inv *= pow(R[i] - L[i] + 1, mod - 2, mod)
    inv %= mod
    
def Gauss(n):
    return n * (n + 1) // 2

ans = 1
for i in range(1, N):
    l0, r0 = L[0], R[0]
    l1, r1 = L[i], R[i]
    temp = 0
    if r0 < l1:
        ans += 1
    elif l0 > r1:
        pass
    else:
        if l0 < l1:
            l0 = l1
        if r0 > r1:
            temp += (r1 - r0) * (r1 - l1 + 1)
            r0 = r1
        temp += Gauss(r1 - l0) - Gauss(r1 - r0 - 1)
        ans += temp * pow((r0 - l0 + 1) * (r1 - l1 + 1), mod - 2, mod)
        ans %= mod

print(ans % mod)
0