結果

問題 No.2875 What is My Rank?
ユーザー t98slidert98slider
提出日時 2024-09-08 07:59:09
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,277 bytes
コンパイル時間 4,756 ms
コンパイル使用メモリ 268,608 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-09-08 07:59:20
合計ジャッジ時間 10,399 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    vector<int> ca(2 * n);
    for(int i = 0; i < n; i++){
        auto &&[l, r] = a[i];
        cin >> l >> r;
        l--;
        ca[2 * i] = l;
        ca[2 * i + 1] = r;
    }
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    const int m = ca.size();
    vector<mint> imos(m);
    for(int i = 0; i < n; i++){
        auto &&[l, r] = a[i];
        mint div = mint(1) / (r - l);
        l = lower_bound(ca.begin(), ca.end(), l) - ca.begin();
        r = lower_bound(ca.begin(), ca.end(), r) - ca.begin();
        if (i == 0) continue;
        imos[r] += div;
        imos[l] -= div;
    }
    mint ans, sv = 1, div = 998244354 / 2;
    for(int i = m - 1; i >= a[0].first + 1; i--){
        imos[i - 1] += imos[i];
        if(i <= a[0].second){
            mint len = ca[i] - ca[i - 1] - 1;
            ans += sv * (ca[i] - ca[i - 1]) + imos[i] * len * (len + 1) * div;
        }
        sv += imos[i] * (ca[i] - ca[i - 1]);
    }
    ans /= ca[a[0].second] - ca[a[0].first];
    cout << ans.val() << '\n';
}
0