結果

問題 No.2336 Do you like typical problems?
ユーザー t98slidert98slider
提出日時 2023-06-03 00:32:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,214 bytes
コンパイル時間 6,099 ms
コンパイル使用メモリ 274,916 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-28 07:02:23
合計ジャッジ時間 9,835 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 RE -
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target("avx512f")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

using S = array<mint, 3>;
using F = array<mint, 3>;
S op(S lhs, S rhs){
    lhs[0] += rhs[0];
    lhs[1] += rhs[1];
    lhs[2] += rhs[2];
    return lhs;
}
S e(){
    S a{};
    return a;
}
S mapping(F f, S x){
    x[0] += f[0] * x[1] + f[1] * x[1] - f[2] * x[2];
    return x;
}
F composition(F f, F g){
    f[0] += g[0];
    f[1] += g[1];
    f[2] += g[2];
    return f;
}
array<mint, 3> ida = {0, 0, 0}, idb = {1, 0, 0};
F id(){return ida;}


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);
    vector<mint> div(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[3 * i + 1] = r;
        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());
    mint div2 = mint(1) / 2;
    for(int i = 0; i + 1 < ca.size(); i++){
        tmp[i][1] = ca[i + 1] - ca[i];
        tmp[i][2] = ((ll)(ca[i + 1]) * (ca[i + 1] - 1) - (ll)(ca[i]) * (ca[i] - 1)) / 2;
    }
    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];
        div[i] = 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)[0] * div[i];
        seg.apply(l, r, {0, div[i] * a[i].second, div[i]});
        seg.apply(0, l, idb);
        b[i] = make_pair(l, r);
    }
    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) = b[i];
        ans += seg.prod(l, r)[0] * div[i];
        seg.apply(l, r, {0, div[i] * a[i].second, div[i]});
        seg.apply(0, l, idb);
    }
    for(int i = 3; i <= n; i++) ans *= i;
    cout << ans.val() << '\n';
}
0