結果

問題 No.1099 Range Square Sum
ユーザー V_MelvilleV_Melville
提出日時 2024-03-06 18:15:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 1,074 bytes
コンパイル時間 5,325 ms
コンパイル使用メモリ 315,436 KB
実行使用メモリ 22,412 KB
最終ジャッジ日時 2024-03-06 18:15:58
合計ジャッジ時間 11,419 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 4 ms
6,676 KB
testcase_16 AC 4 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 4 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 4 ms
6,676 KB
testcase_21 AC 292 ms
22,412 KB
testcase_22 AC 292 ms
22,412 KB
testcase_23 AC 288 ms
22,412 KB
testcase_24 AC 292 ms
22,412 KB
testcase_25 AC 289 ms
22,412 KB
testcase_26 AC 268 ms
22,412 KB
testcase_27 AC 268 ms
22,412 KB
testcase_28 AC 270 ms
22,412 KB
testcase_29 AC 268 ms
22,412 KB
testcase_30 AC 271 ms
22,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

struct S {
    ll x, x2;
    int size;
    S(ll x=0, ll x2=0, int size=0): x(x), x2(x2), size(size) {}
};
S op(S a, S b) { return S(a.x+b.x, a.x2+b.x2, a.size+b.size); }
S e() { return S(); }

S mapping(ll f, S s) { return S(s.x + f*s.size, s.x2 + 2*f*s.x + f*f*s.size, s.size); }
ll composition(ll g, ll f) { return f+g; }
ll id() { return 0; }

int main() {
    int n;
    cin >> n;
    
    vector<S> a;
    rep(i, n) {
        ll x; cin >> x;
        a.emplace_back(x, x*x, 1);
    }
    
    int q;
    cin >> q;
    lazy_segtree<S, op, e, ll, mapping, composition, id> t(a);
    rep(qi, q) {
        int type, l, r;
        cin >> type >> l >> r;
        --l;
        if (type == 1) {
            int x;
            cin >> x;
            t.apply(l, r, x);
        }
        else {
            cout << t.prod(l, r).x2 << '\n';
        }
    }
    
    return 0;
}
0