結果

問題 No.1548 [Cherry 2nd Tune B] 貴方と私とサイクルとモーメント
ユーザー りあんりあん
提出日時 2021-06-11 22:54:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 4,500 ms
コード長 2,617 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 221,680 KB
実行使用メモリ 31,232 KB
最終ジャッジ日時 2024-05-08 19:05:47
合計ジャッジ時間 10,285 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 144 ms
17,024 KB
testcase_03 AC 38 ms
10,240 KB
testcase_04 AC 128 ms
30,720 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 100 ms
16,768 KB
testcase_07 AC 113 ms
31,232 KB
testcase_08 AC 147 ms
17,280 KB
testcase_09 AC 99 ms
10,496 KB
testcase_10 AC 91 ms
30,464 KB
testcase_11 AC 106 ms
30,720 KB
testcase_12 AC 62 ms
6,784 KB
testcase_13 AC 60 ms
30,720 KB
testcase_14 AC 97 ms
10,112 KB
testcase_15 AC 61 ms
31,104 KB
testcase_16 AC 114 ms
17,280 KB
testcase_17 AC 147 ms
30,592 KB
testcase_18 AC 115 ms
30,976 KB
testcase_19 AC 51 ms
10,240 KB
testcase_20 AC 80 ms
30,976 KB
testcase_21 AC 90 ms
16,896 KB
testcase_22 AC 185 ms
31,232 KB
testcase_23 AC 194 ms
31,232 KB
testcase_24 AC 190 ms
31,232 KB
testcase_25 AC 187 ms
31,232 KB
testcase_26 AC 185 ms
31,104 KB
testcase_27 AC 191 ms
31,232 KB
testcase_28 AC 193 ms
31,104 KB
testcase_29 AC 192 ms
31,232 KB
testcase_30 AC 197 ms
31,232 KB
testcase_31 AC 201 ms
31,232 KB
testcase_32 AC 109 ms
31,232 KB
testcase_33 AC 168 ms
31,232 KB
testcase_34 AC 132 ms
31,232 KB
testcase_35 AC 149 ms
31,104 KB
testcase_36 AC 145 ms
31,104 KB
testcase_37 AC 223 ms
31,232 KB
testcase_38 AC 105 ms
31,232 KB
testcase_39 AC 162 ms
31,232 KB
testcase_40 AC 124 ms
31,232 KB
testcase_41 AC 143 ms
31,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/modint>
#include<atcoder/lazysegtree>
using namespace std;

using mint = atcoder::modint998244353;

using S = pair<mint, int>;

S op(S a, S b) {
    return { a.first + b.first, a.second + b.second };
}
S e() {
    return S(0, 0);
}
S mapping(int a, S b) {
    return a == -1 ? b : S(mint(a) * b.second, b.second);
}
int composition(int a, int b) {
    return a == -1 ? b : a;
}
int id() {
    return -1;
}

vector<atcoder::lazy_segtree<S, op, e, int, mapping, composition, id>> sg(5);

mint prod(int type, const vector<pair<int, int>>& segs) {
    mint res(0);
    for (auto& s : segs) {
        res += sg[type].prod(s.first, s.second).first;
    }
    return res;
}

mint calc(int type, const vector<pair<int, int>>& segs) {
    mint s0 = prod(0, segs);
    mint s1 = prod(1, segs);
    mint m = s1 / s0;
    if (type == 1) {
        return (s1 - s0 * m) / s0;
    }
    else if (type == 2) {
        mint s2 = prod(2, segs);
        return (s2 - s1 * m * 2 + s0 * m * m) / s0;
    }
    else if (type == 3) {
        mint s2 = prod(2, segs);
        mint s3 = prod(3, segs);
        return (s3 - s2 * m * 3 + s1 * m * m * 3 - s0 * m * m * m) / s0;
    }
    else {
        mint s2 = prod(2, segs);
        mint s3 = prod(3, segs);
        mint s4 = prod(4, segs);
        return (s4 - s3 * m * 4 + s2 * m * m * 6 - s1 * m * m * m * 4 + s0 * m * m * m * m) / s0;
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<S> a2(n, {1, 1});
    for (int i = 0; i < 5; ++i) {
        sg[i] = atcoder::lazy_segtree<S, op, e, int, mapping, composition, id>(a2);
        for (int j = 0; j < n; ++j) {
            a2[j].first *= a[j];
        }
    }
    int q;
    cin >> q;
    for (int _ = 0; _ < q; ++_) {
        int t, u, v, w;
        cin >> t >> u >> v >> w;
        --u;
        --v;
        --w;
        vector<pair<int, int>> segs;
        if (u > v) swap(u, v);
        if (u < w && w < v) {
            segs.emplace_back(u, v + 1);
        }
        else {
            segs.emplace_back(v, n);
            segs.emplace_back(0, u + 1);
        }
        if (t == 0) {
            int b;
            cin >> b;
            mint mb(1);
            for (int i = 0; i < 5; ++i) {
                for (auto& s : segs) {
                    sg[i].apply(s.first, s.second, mb.val());
                }
                mb *= b;
            }
        }
        else {
            cout << calc(t, segs).val() << '\n';
        }
    }


    return 0;
}
0