結果

問題 No.1099 Range Square Sum
ユーザー chineristACchineristAC
提出日時 2020-06-27 00:14:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,735 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 107,064 KB
最終ジャッジ日時 2023-09-18 09:52:17
合計ジャッジ時間 15,686 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
76,228 KB
testcase_01 AC 74 ms
71,488 KB
testcase_02 AC 73 ms
71,444 KB
testcase_03 AC 73 ms
71,468 KB
testcase_04 AC 73 ms
71,912 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 72 ms
71,968 KB
testcase_09 AC 71 ms
71,688 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 TLE -
testcase_28 TLE -
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
            #print("HDHDH",q,L,R)
            for i in range(q*n,min(N,n*(q+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

def showA():
    res=[A[i] for i in range(N)]
    for i in range(N):
        q=i//n
        res[i]+=Adata[q]
    print(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)
        #showA()
        #print(RSQdata)
        #print(RSSQdata)
    else:
        i,l,r=q
        l-=1;r-=1
        #print("ANS")
        print(RSSQ(l,r))
0