結果

問題 No.2875 What is My Rank?
ユーザー tottoripapertottoripaper
提出日時 2024-09-12 12:12:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,390 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 211,968 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-12 12:12:54
合計ジャッジ時間 7,005 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 59 ms
6,940 KB
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using ll = std::int64_t;

std::tuple<ll, ll, ll> extgcd(ll a, ll b){
    ll s1 = 1, t1 = 0, s2 = 0, t2 = 1;
    while(b != 0){
        std::tie(s1, t1, s2, t2) = std::make_tuple(s2, t2, s1 - (a / b) * s2, t1 - (a / b) * t2);
        std::tie(a, b) = std::make_tuple(b, a % b);
    }
    return std::make_tuple(s1, t1, a);
}

ll inv(ll a, ll n){
    ll inv_a;
    std::tie(inv_a, std::ignore, std::ignore) = extgcd(a, n);
    inv_a %= n;
    if(inv_a < 0){inv_a += n;}
    return inv_a;
}

ll f(int n){
    return 1ll * n * (n + 1) / 2;
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int N;
    std::cin >> N;

    std::vector<int> l(N), r(N);
    for(int i=0;i<N;i++){
        std::cin >> l[i] >> r[i];
    }

    constexpr ll MOD = 998'244'353;
    ll res = 1;
    ll inv_n1 = inv(r[0] - l[0] + 1, MOD);
    for(int i=1;i<N;i++){
        ll inv_ni = inv(r[i] - l[i] + 1, MOD);

        int l1 = std::max(l[i], r[0] + 1);
        if(l1 <= r[i]){
            res += 1ll * (r[i] - l1 + 1) * inv_ni;
            if(res >= MOD){res -= MOD;}
        }

        int l2 = std::max(l[i], l[0]);
        int r2 = std::min(r[i], r[0]);
        if(l2 <= r2){
            res += (f(r2 - l[0]) - f(l2 - 1 - l[0])) * inv_n1 % MOD * inv_ni % MOD;
            if(res >= MOD){res -= MOD;}
        }
    }

    std::cout << res << std::endl;
}
0