結果

問題 No.1099 Range Square Sum
ユーザー carrot46carrot46
提出日時 2020-06-26 22:39:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,185 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 169,228 KB
実行使用メモリ 4,908 KB
最終ジャッジ日時 2023-09-18 06:14:47
合計ジャッジ時間 7,777 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,652 KB
testcase_01 AC 3 ms
4,656 KB
testcase_02 AC 3 ms
4,560 KB
testcase_03 AC 3 ms
4,692 KB
testcase_04 AC 3 ms
4,620 KB
testcase_05 AC 3 ms
4,628 KB
testcase_06 AC 3 ms
4,636 KB
testcase_07 AC 3 ms
4,908 KB
testcase_08 AC 3 ms
4,556 KB
testcase_09 AC 3 ms
4,632 KB
testcase_10 AC 2 ms
4,720 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    const int bnum = 450, bsize = 450, max_n = bnum * bsize;
    cin >> N;
    vec a(max_n, 0);
    rep(i,N) cin>>a[i];
    vec as(bnum, 0), as2(bnum, 0), tx(bnum, 0);
    rep(i,N){
        as[i / bsize] += a[i];
        as2[i / bsize] += a[i] * a[i];
    }
    cin>>Q;
    rep(_,Q){
        int q, l, r, x;
        cin>>q>>l>>r;
        --l; --r;
        int lb = l / bsize, rb = r / bsize;
        if(q == 1){
            cin>>x;
            if(lb < rb) {
                reps(i, lb * bsize, (lb + 1) * bsize) {
                    int temp = (i >= l ? x : 0);
                    as2[lb] += (a[i] + tx[lb] + temp) * (a[i] + tx[lb] + temp) - a[i] * a[i];
                    as[lb] += tx[lb] + temp;
                    a[i] += tx[lb] + temp;
                }
                reps(i, rb * bsize, (rb + 1) * bsize) {
                    int temp = (i <= r ? x : 0);
                    as2[rb] += (a[i] + tx[rb] + temp) * (a[i] + tx[rb] + temp) - a[i] * a[i];
                    as[rb] += tx[rb] + temp;
                    a[i] += tx[rb] + temp;
                }
                tx[lb] = tx[rb] = 0;
                reps(i, lb + 1, rb) tx[i] += x;
            }else{
                reps(i, lb * bsize, (lb + 1) * bsize) {
                    int temp = (i >= l && i <= r ? x : 0);
                    as2[lb] += (a[i] + tx[lb] + temp) * (a[i] + tx[lb] + temp) - a[i] * a[i];
                    as[lb] += tx[lb] + temp;
                    a[i] += tx[lb] + temp;
                }
                tx[lb] = 0;
            }
        }else{
            ll res = 0;
            if(lb < rb) {
                as[lb] += tx[lb] * bsize;
                as[rb] += tx[rb] * bsize;
                reps(i, lb * bsize, (lb + 1) * bsize) {
                    as2[lb] += (a[i] + tx[lb]) * (a[i] + tx[lb]) - a[i] * a[i];
                    a[i] += tx[lb];
                    if (i >= l) res += a[i] * a[i];
                }
                reps(i, rb * bsize, (rb + 1) * bsize) {
                    as2[rb] += (a[i] + tx[rb]) * (a[i] + tx[rb]) - a[i] * a[i];
                    a[i] += tx[rb];
                    if (i <= r) res += a[i] * a[i];
                }
                tx[lb] = tx[rb] = 0;
                reps(i, lb + 1, rb) res += as2[i] + 2LL * as[i] * tx[i] + tx[i] * tx[i];
            }else{
                as[lb] += tx[lb] * bsize;
                reps(i, lb * bsize, (lb + 1) * bsize) {
                    as2[lb] += (a[i] + tx[lb]) * (a[i] + tx[lb]) - a[i] * a[i];
                    a[i] += tx[lb];
                    if(i >= l && i <= r) res += a[i] * a[i];
                }
                tx[lb] = 0;
            }
            cout<<res<<endl;
        }
    }
}
0