結果

問題 No.1099 Range Square Sum
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-31 02:40:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 879 bytes
コンパイル時間 2,469 ms
コンパイル使用メモリ 211,120 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-03-31 02:40:53
合計ジャッジ時間 8,289 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 1 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 4 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 3 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 310 ms
22,400 KB
testcase_22 AC 295 ms
22,400 KB
testcase_23 AC 299 ms
22,400 KB
testcase_24 AC 294 ms
22,400 KB
testcase_25 AC 321 ms
22,400 KB
testcase_26 AC 271 ms
22,400 KB
testcase_27 AC 263 ms
22,400 KB
testcase_28 AC 268 ms
22,400 KB
testcase_29 AC 276 ms
22,400 KB
testcase_30 AC 263 ms
22,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
	}
}
0