結果

問題 No.1099 Range Square Sum
ユーザー たたき@競プロ
提出日時 2023-09-15 19:02:12
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 323 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 4,719 ms
コンパイル使用メモリ 314,160 KB
実行使用メモリ 22,400 KB
最終ジャッジ日時 2024-07-02 20:57:00
合計ジャッジ時間 10,411 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
struct s{ll a,b; int r;};
s op(s sa,s sb){
  s res;
  res.a=sa.a+sb.a; res.b=sa.b+sb.b; res.r=sa.r+sb.r;
  return res;
}
s e(){
  s res={0,0,0};
  return res;
}
s mapping(ll f,s x){
  x.b+=x.a*2*f+x.r*f*f;
  x.a+=f*x.r;
  return x;
}
ll comp(ll fa,ll fb){return fa+fb;}
ll id(){return 0ll;}
int main(){
  int n;cin>>n;
  lazy_segtree<s,op,e,ll,mapping,comp,id>sg(n);
  rep(i,n){
    ll a;cin>>a;
    sg.set(i,{a,a*a,1});
  }
  int q;cin>>q;
  rep(z,q){
    int t;cin>>t;
    if(t==1){
      ll l,r,x;cin>>l>>r>>x;
      sg.apply(l-1,r,x);
    }
    else{
      ll l,r;cin>>l>>r;
      s res=sg.prod(l-1,r);
      cout<<res.b<<"\n";
    }
  }
}
    
0