結果

問題 No.1099 Range Square Sum
ユーザー chineristACchineristAC
提出日時 2020-06-26 23:56:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,500 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 106,844 KB
最終ジャッジ日時 2023-09-18 09:14:09
合計ジャッジ時間 15,608 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,512 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 74 ms
71,652 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 76 ms
71,596 KB
testcase_10 WA -
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 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input=sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
n=int(N**.5)

Adata=[0]*((N-1)//n+1)
RSQdata=[0]*((N-1)//n+1)
RSSQdata=[0]*((N-1)//n+1)
for i in range(N):
    q=i//n
    RSQdata[q]+=A[i]
    RSSQdata[q]+=A[i]**2

def update(l,r,x):
    id=l
    while id<=r:
        L=id
        q=id//n
        R=min((q+1)*n-1,r)
        if R-L+1==n:
            Adata[q]+=x
            RSQdata[q]+=x*n
            RSSQdata[q]+=2*x*RSQ(L,R+1)-n*x**2
        else:
            for i in range(L,R+1):
                A[i]+=x
            RSQdata[q]+=(R-L+1)*x
            res=0
            for i in range(q*n,R+1):
                res+=(A[i]+Adata[q])**2
            RSSQdata[q]=res
        id=R+1

def RSQ(l,r):
    id=l
    res=0
    while id<=r:
        L=id
        q=id//n
        R=min((q+1)*n-1,r)
        if R-L+1==n:
            res+=RSQdata[q]
        else:
            for i in range(L,R+1):
                res+=A[i]+Adata[q]
        id=R+1

    return res

def RSSQ(l,r):
    id=l
    res=0
    while id<=r:
        L=id
        q=id//n
        R=min((q+1)*n-1,r)
        if R-L+1==n:
            res+=RSSQdata[q]
        else:
            for i in range(L,R+1):
                res+=(A[i]+Adata[q])**2
        id=R+1

    return res

for _ in range(int(input())):
    q=tuple(map(int,input().split()))
    if q[0]==1:
        i,l,r,x=q
        l-=1;r-=1
        update(l,r,x)
    else:
        i,l,r=q
        l-=1;r-=1
        #print("ANS")
        print(RSSQ(l,r))
0