結果
問題 | No.1099 Range Square Sum |
ユーザー |
|
提出日時 | 2021-10-19 20:04:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 386 ms / 2,000 ms |
コード長 | 1,317 bytes |
コンパイル時間 | 4,594 ms |
コンパイル使用メモリ | 256,216 KB |
最終ジャッジ日時 | 2025-01-25 01:55:09 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 30 |
ソースコード
#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 998244353typedef 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;}}}