結果

問題 No.1099 Range Square Sum
ユーザー ああいいああいい
提出日時 2022-01-07 17:15:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,896 ms / 2,000 ms
コード長 1,703 bytes
コンパイル時間 389 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 140,092 KB
最終ジャッジ日時 2024-04-26 14:16:10
合計ジャッジ時間 18,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,268 KB
testcase_01 AC 37 ms
53,012 KB
testcase_02 AC 38 ms
53,804 KB
testcase_03 AC 38 ms
53,692 KB
testcase_04 AC 38 ms
53,260 KB
testcase_05 AC 37 ms
53,792 KB
testcase_06 AC 38 ms
53,568 KB
testcase_07 AC 35 ms
52,956 KB
testcase_08 AC 37 ms
53,200 KB
testcase_09 AC 36 ms
54,204 KB
testcase_10 AC 37 ms
52,756 KB
testcase_11 AC 128 ms
77,464 KB
testcase_12 AC 112 ms
77,408 KB
testcase_13 AC 120 ms
77,448 KB
testcase_14 AC 112 ms
77,392 KB
testcase_15 AC 121 ms
77,500 KB
testcase_16 AC 106 ms
77,516 KB
testcase_17 AC 110 ms
77,240 KB
testcase_18 AC 110 ms
77,188 KB
testcase_19 AC 110 ms
77,004 KB
testcase_20 AC 146 ms
77,988 KB
testcase_21 AC 1,699 ms
137,992 KB
testcase_22 AC 1,703 ms
138,512 KB
testcase_23 AC 1,771 ms
138,192 KB
testcase_24 AC 1,870 ms
137,968 KB
testcase_25 AC 1,896 ms
138,700 KB
testcase_26 AC 1,180 ms
138,536 KB
testcase_27 AC 1,191 ms
138,680 KB
testcase_28 AC 1,135 ms
138,096 KB
testcase_29 AC 1,066 ms
138,304 KB
testcase_30 AC 1,242 ms
140,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
r = sys.stdin
N = int(r.readline())
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,r.readline().split()))
    if l[0] == 1:
        update(l[1]-1,l[2],l[3])
    else:
        print(query(l[1]-1,l[2]))
"""
def write():
    for i in range(N):
        print(query(i,i+1))
def write2():
    for i in range(N):
        query(i,i+1)
        print(dat[i+n-1][0],end = " ")
    print()
for _ in range(Q):
    l = list(map(int,input().split()))
    if l[0] == 1:update(l[1]-1,l[2],l[3])
    else:
        write2()
"""
0