結果
問題 | No.1099 Range Square Sum |
ユーザー |
|
提出日時 | 2024-03-31 02:40:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 349 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 2,281 ms |
コンパイル使用メモリ | 201,688 KB |
最終ジャッジ日時 | 2025-02-20 16:06:22 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/lazysegtree>using namespace std;using namespace atcoder;using ll = long long;struct S {ll sm;ll sm2;ll size;};S op(S a, S b) {return S {a.sm + b.sm, a.sm2 + b.sm2, a.size + b.size};}S mapping(ll f, S x) {return S {x.sm + (f * x.size), x.sm2 + (f *f * x.size) + (2 * f * x.sm), x.size};}ll composition(ll f, ll g) {return f + g;}S e() {return S {0LL, 0LL, 0LL};}ll id() {return 0;}int main() {int N;cin >> N;vector<S> A(N + 1, {0LL, 0LL, 1});for (int i = 1;i <= N;i++) {ll a;cin >> a;A[i].sm = a;A[i].sm2 = a * a;}lazy_segtree<S, op, e,ll, mapping, composition, id> seg(A);int Q;cin >> Q;while (Q--) {int op;cin >> op;if (op == 1) {int l, r;ll x;cin >> l >> r >> x;seg.apply(l, r + 1, x);continue;}int l, r;cin >> l >> r;cout << seg.prod(l, r + 1).sm2 << endl;}}