結果

問題 No.2336 Do you like typical problems?
ユーザー t98slidert98slider
提出日時 2023-06-03 00:55:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 911 ms / 2,000 ms
コード長 1,911 bytes
コンパイル時間 3,997 ms
コンパイル使用メモリ 240,960 KB
実行使用メモリ 31,512 KB
最終ジャッジ日時 2023-08-28 07:11:19
合計ジャッジ時間 10,854 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 7 ms
4,376 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 911 ms
31,324 KB
testcase_14 AC 893 ms
31,420 KB
testcase_15 AC 893 ms
31,396 KB
testcase_16 AC 901 ms
31,404 KB
testcase_17 AC 889 ms
31,368 KB
testcase_18 AC 113 ms
8,036 KB
testcase_19 AC 124 ms
7,824 KB
testcase_20 AC 709 ms
31,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using S = pair<mint, mint>;
using F = mint;
S op(S lhs, S rhs){
    return make_pair(lhs.first + rhs.first, lhs.second + rhs.second);
}
S e(){
    return make_pair(0, 0);
}
S mapping(F f, S x){
    return make_pair(x.first + f * x.second, x.second);
}
F composition(F f, F g){
    return f + g;
}
F id(){return 0;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int,int>> a(n), b(n);
    vector<int> ca(2 * n);
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        a[i] = make_pair(l, r);
        ca[2 * i] = l;
        ca[2 * i + 1] = r + 1;
    }
    sort(ca.begin(), ca.end());
    ca.erase(unique(ca.begin(), ca.end()), ca.end());
    vector<S> tmp(ca.size());
    for(int i = 0; i + 1 < ca.size(); i++){
        tmp[i].second = ca[i + 1] - ca[i];
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(tmp);
    mint ans;
    for(int i = 0; i < n; i++){
        int l, r;
        tie(l, r) = a[i];
        mint div = mint(1) / (r - l + 1);
        l = lower_bound(ca.begin(), ca.end(), l) - ca.begin();
        r = upper_bound(ca.begin(), ca.end(), r) - ca.begin();
        ans += seg.prod(l, r).first * div;
        seg.apply(l, r, div);
    }
    seg = lazy_segtree<S, op, e, F, mapping, composition, id>(tmp);
    for(int i = n - 1; i >= 0; i--){
        int l, r;
        tie(l, r) = a[i];
        mint div = mint(1) / (r - l + 1);
        l = lower_bound(ca.begin(), ca.end(), l) - ca.begin();
        r = upper_bound(ca.begin(), ca.end(), r) - ca.begin();
        ans += seg.prod(l, r).first * div;
        seg.apply(l, r, div);
    }
    ans = mint(n) * (n - 1) - ans;
    ans /= 2;
    for(int i = 3; i <= n; i++) ans *= i;
    cout << ans.val() << '\n';
}
0