結果

問題 No.1099 Range Square Sum
ユーザー rin204
提出日時 2022-04-17 18:10:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 202,732 KB
最終ジャッジ日時 2025-01-28 18:57:38
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct S{
    int len;
    long long tot;
    long long sqtot;
};

using F = int;

S op(S l, S r){
    return S{l.len + r.len, l.tot + r.tot, l.sqtot + r.sqtot};
}

S e(){
    return S{0, 0, 0};
}

S mapping(F l, S r){
    return S{r.len, r.tot + l * r.len, r.sqtot + 2 * r.tot * l + r.len * l * l};
}

F composition(F l, F r){
    return l + r;
}

F id(){
    return 0;
}

int main(void){
    int n;
    cin >> n;
    vector<S> A(n);
    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        A[i] = S{1, a, a * a};
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
    int Q;
    cin >> Q;
    int t, l, r, x;
    while(Q--){
        cin >> t >> l >> r;
        if(t == 1){
            cin >> x;
            seg.apply(l - 1, r, x);
        }
        else{
            auto ans = seg.prod(l - 1, r);
            cout << ans.sqtot << "\n";

        }

    }
    
}
0