結果

問題 No.877 Range ReLU Query
ユーザー titiatitia
提出日時 2019-09-06 23:00:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 774 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 425 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 114,200 KB
最終ジャッジ日時 2023-08-08 04:24:29
合計ジャッジ時間 11,504 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,492 KB
testcase_01 AC 93 ms
76,632 KB
testcase_02 AC 86 ms
76,336 KB
testcase_03 AC 94 ms
76,528 KB
testcase_04 AC 74 ms
75,532 KB
testcase_05 AC 81 ms
76,296 KB
testcase_06 AC 84 ms
76,168 KB
testcase_07 AC 83 ms
76,196 KB
testcase_08 AC 102 ms
77,424 KB
testcase_09 AC 76 ms
75,516 KB
testcase_10 AC 84 ms
76,096 KB
testcase_11 AC 706 ms
111,888 KB
testcase_12 AC 636 ms
111,644 KB
testcase_13 AC 530 ms
105,536 KB
testcase_14 AC 559 ms
103,756 KB
testcase_15 AC 758 ms
112,548 KB
testcase_16 AC 757 ms
112,404 KB
testcase_17 AC 765 ms
110,336 KB
testcase_18 AC 774 ms
112,100 KB
testcase_19 AC 688 ms
111,088 KB
testcase_20 AC 767 ms
114,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())
A=list(map(int,input().split()))
Query=[list(map(int,input().split())) for i in range(Q)]

# BIT(BIT-indexed tree)
LEN=N

BIT=[0]*(LEN+1)# 1-indexedなtree

def update(v,w):# index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

BIT2=[0]*(LEN+1)# 1-indexedなtree

def update2(v,w):# index vにwを加える
    while v<=LEN:
        BIT2[v]+=w
        v+=(v&(-v))# 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue2(v):# [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT2[v]
        v-=(v&(-v))# 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS


ALL=[(x,i) for i,x in enumerate(A)]

for ind,(_,l,r,x) in enumerate(Query):
    ALL.append((x,l,r,ind))

ALL.sort(reverse=True)

ANS=[0]*Q

for a in ALL:
    if len(a)==2:
        update(a[1]+1,a[0])
        update2(a[1]+1,1)
    else:
        ANS[a[3]]=getvalue(a[2])-getvalue(a[1]-1)-a[0]*(getvalue2(a[2])-getvalue2(a[1]-1))

for ans in ANS:
    print(ans)
        
0