結果

問題 No.1099 Range Square Sum
ユーザー ああいいああいい
提出日時 2022-01-07 15:31:45
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,369 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 138,768 KB
最終ジャッジ日時 2023-08-08 20:04:53
合計ジャッジ時間 21,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)

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

n = 1
while n < N:
    n <<= 1
dat = [[0] * 2 for _ in range(2 * n - 1)]
lazy = [0] * (2 * n - 1)

for i in range(N):
    j = i + n -1
    dat[j][0] = A[i]
    dat[j][1] = A[i] ** 2
def make():
    for k in reversed(range(n-1)):
        dat[k][0] = dat[k*2+1][0] + dat[k*2+2][0]
        dat[k][1] = dat[k*2+1][1] + dat[k*2+2][1]
make()

def eval(k,l,r):
    if lazy[k] == 0:return
    if k < n-1:
        lazy[k*2+1] = lazy[k]
        lazy[k*2+2] = lazy[k]
    x = lazy[k]
    dat[k][1] += 2 *  dat[k][0] * x + x * x * (r-l)
    dat[k][0] += x * (r-l)
    lazy[k] = 0
def update(a,b,x,k=0,l=0,r=n):
    eval(k,l,r)
    if r <= a or b <= l:return
    if a <= l and r <= b:
        lazy[k] = x
        eval(k,l,r)
        return
    update(a,b,x,k*2+1,l,(l+r)//2)
    update(a,b,x,k*2+2,(l+r)//2,r)
    dat[k][0] =dat[k*2+1][0]+dat[k*2+2][0]
    dat[k][1] = dat[k*2+1][1]+dat[k*2+2][1]
def query(a,b,k=0,l=0,r=n):
    eval(k,l,r)
    if r <= a or b <= l:return 0
    if a <= l and r <= b:
        return dat[k][1]
    v1 = query(a,b,k*2+1,l,(l+r)//2)
    v2 = query(a,b,k*2+2,(l+r)//2,r)
    return v1+v2
Q = int(input())
for _ in range(Q):
    l = list(map(int,input().split()))
    if l[0] == 1:
        update(l[1]-1,l[2],l[3])
    else:
        print(query(l[1]-1,l[2]))
0