結果

問題 No.1099 Range Square Sum
ユーザー yurujirouyurujirou
提出日時 2021-10-19 20:04:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 345 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 4,561 ms
コンパイル使用メモリ 269,024 KB
実行使用メモリ 26,616 KB
最終ジャッジ日時 2023-10-20 10:50:27
合計ジャッジ時間 9,518 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,844 KB
testcase_01 AC 2 ms
7,844 KB
testcase_02 AC 3 ms
7,844 KB
testcase_03 AC 3 ms
7,844 KB
testcase_04 AC 2 ms
7,844 KB
testcase_05 AC 2 ms
7,844 KB
testcase_06 AC 2 ms
7,844 KB
testcase_07 AC 3 ms
7,844 KB
testcase_08 AC 3 ms
7,844 KB
testcase_09 AC 3 ms
7,844 KB
testcase_10 AC 3 ms
7,844 KB
testcase_11 AC 5 ms
7,916 KB
testcase_12 AC 5 ms
7,916 KB
testcase_13 AC 5 ms
7,916 KB
testcase_14 AC 5 ms
7,916 KB
testcase_15 AC 5 ms
7,916 KB
testcase_16 AC 5 ms
7,916 KB
testcase_17 AC 5 ms
7,916 KB
testcase_18 AC 5 ms
7,916 KB
testcase_19 AC 5 ms
7,916 KB
testcase_20 AC 5 ms
7,916 KB
testcase_21 AC 341 ms
26,616 KB
testcase_22 AC 345 ms
26,616 KB
testcase_23 AC 340 ms
26,616 KB
testcase_24 AC 340 ms
26,616 KB
testcase_25 AC 342 ms
26,616 KB
testcase_26 AC 297 ms
26,616 KB
testcase_27 AC 295 ms
26,616 KB
testcase_28 AC 296 ms
26,616 KB
testcase_29 AC 298 ms
26,616 KB
testcase_30 AC 297 ms
26,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define RREP(i,n) for(int i = (int)n-1; i >= 0; i--)
#define LREP(i,n) for(LL i = 0; i < (LL)n; i++)

#define Vi vector<int>
#define Vl vector<long long>
#define P pair<int, int>
#define LP pair<long long ,long long>
#define T3 tuple<LL, LL, LL>
#define T4 tuple<LL, LL, LL, LL>
#define INF 1000000007
#define SIZE 300010
#define MOD 998244353
typedef long long LL;

struct S
{
	LL val = 0, d = 0, sum = 0;
};

S op(S a, S b) {
	return S{ a.val + b.val,a.d + b.d,a.sum + b.sum };
}

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

S mapping(LL f, S x) {
	S res = e();
	res.val = x.val + 2 * f * x.sum + f * f * x.d;
	res.d = x.d;
	res.sum = f * x.d + x.sum;
	return res;
}

LL composition(LL f, LL g) {
	return f + g;
}

LL id() {
	return 0;
}

LL N;
LL A[SIZE], sum[SIZE];

int main() {
	cin >> N;
	REP(i, N) cin >> A[i];
	lazy_segtree<S, op, e, LL, mapping, composition, id> seg(N);
	REP(i, N) {
		seg.set(i, S{ A[i] * A[i],1,A[i] });
	}

	int Q; cin >> Q;
	REP(q, Q) {
		LL t, l, r, x;
		cin >> t >> l >> r;
		if (t == 1) {
			cin >> x;
			seg.apply(l - 1, r, x);
		}
		else {
			cout << seg.prod(l - 1, r).val << endl;
		}
	}
}
0