結果

問題 No.1099 Range Square Sum
ユーザー 👑 rin204rin204
提出日時 2022-04-17 18:13:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 206,632 KB
実行使用メモリ 22,236 KB
最終ジャッジ日時 2023-08-27 03:52:17
合計ジャッジ時間 6,895 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 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,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 300 ms
22,116 KB
testcase_22 AC 298 ms
22,112 KB
testcase_23 AC 301 ms
22,236 KB
testcase_24 AC 301 ms
22,156 KB
testcase_25 AC 298 ms
22,096 KB
testcase_26 AC 262 ms
22,208 KB
testcase_27 AC 262 ms
22,180 KB
testcase_28 AC 262 ms
22,232 KB
testcase_29 AC 264 ms
22,116 KB
testcase_30 AC 263 ms
22,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

using F = long long;

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);
    long long 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;
    long long 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