結果
| 問題 | No.1099 Range Square Sum |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-01-18 19:02:17 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 319 ms / 2,000 ms |
| コード長 | 725 bytes |
| 記録 | |
| コンパイル時間 | 3,387 ms |
| コンパイル使用メモリ | 345,916 KB |
| 実行使用メモリ | 22,304 KB |
| 最終ジャッジ日時 | 2026-01-18 19:02:26 |
| 合計ジャッジ時間 | 8,050 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/lazysegtree>
using ll=long long;
struct S{
ll sqr,sum,len;
};
int main(){
int N;cin>>N;
vector<S> init(N);
for(int i=0;i<N;i++){
ll a;cin>>a;
init[i]={a*a,a,1};
}
atcoder::lazy_segtree<S,
[](S a,S b){return S{a.sqr+b.sqr,a.sum+b.sum,a.len+b.len};},
[]{return S{0,0,0};},
ll,
[](ll f,S x){return S{x.sqr+x.sum*f*2+f*f*x.len,x.sum+f*x.len,x.len};},
[](ll f,ll g){return f+g;},
[]{return 0;}> seg(init);
int Q;cin>>Q;
while(Q--){
ll com,l,r,x;
cin>>com>>l>>r;
l--;
if(com==1){
cin>>x;
seg.apply(l,r,x);
}
else if(com==2){
cout<<seg.prod(l,r).sqr<<endl;
}
}
}