結果
問題 | No.1099 Range Square Sum |
ユーザー |
![]() |
提出日時 | 2024-06-18 13:31:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 155 ms / 2,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 2,305 ms |
コンパイル使用メモリ | 200,932 KB |
最終ジャッジ日時 | 2025-02-21 23:14:33 |
ジャッジサーバーID (参考情報) |
judge1 / 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";}}}