結果
問題 | No.1099 Range Square Sum |
ユーザー | eve__fuyuki |
提出日時 | 2024-06-18 13:31:59 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 2,950 ms |
コンパイル使用メモリ | 210,460 KB |
実行使用メモリ | 22,312 KB |
最終ジャッジ日時 | 2024-06-18 13:32:07 |
合計ジャッジ時間 | 7,382 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include <atcoder/lazysegtree> using namespace atcoder; struct S { long long aa, a, len; }; S op(S a, S b) { return {a.aa + b.aa, a.a + b.a, a.len + b.len}; } S e() { return {0, 0, 0}; } S mapping(long long f, S x) { return {x.aa + 2 * f * x.a + f * f * x.len, x.a + f * x.len, x.len}; } long long composition(long long f, long long g) { return f + g; } long long id() { return 0; } int main() { fast_io(); int n; cin >> n; vector<S> v(n); for (int i = 0; i < n; i++) { long long a; cin >> a; v[i] = {a * a, a, 1}; } lazy_segtree<S, op, e, long long, mapping, composition, id> seg(v); int q; cin >> q; for (; q--;) { int type, l, r; cin >> type >> l >> r; l--; if (type == 1) { long long x; cin >> x; seg.apply(l, r, x); } if (type == 2) { cout << seg.prod(l, r).aa << "\n"; } } }