結果

問題 No.1099 Range Square Sum
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-15 19:02:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 6,111 ms
コンパイル使用メモリ 311,052 KB
実行使用メモリ 22,480 KB
最終ジャッジ日時 2023-09-15 19:02:48
合計ジャッジ時間 12,959 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 4 ms
4,376 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 331 ms
22,480 KB
testcase_22 AC 326 ms
22,144 KB
testcase_23 AC 334 ms
22,136 KB
testcase_24 AC 331 ms
22,204 KB
testcase_25 AC 328 ms
22,184 KB
testcase_26 AC 291 ms
22,204 KB
testcase_27 AC 298 ms
22,272 KB
testcase_28 AC 291 ms
22,184 KB
testcase_29 AC 296 ms
22,244 KB
testcase_30 AC 295 ms
22,212 KB
権限があれば一括ダウンロードができます

ソースコード

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