結果

問題 No.877 Range ReLU Query
ユーザー titiatitia
提出日時 2019-09-06 22:59:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,725 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 11,088 KB
実行使用メモリ 64,224 KB
最終ジャッジ日時 2023-09-07 02:06:48
合計ジャッジ時間 17,127 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,340 KB
testcase_01 AC 21 ms
8,512 KB
testcase_02 AC 21 ms
8,464 KB
testcase_03 AC 22 ms
8,516 KB
testcase_04 AC 18 ms
8,240 KB
testcase_05 AC 19 ms
8,112 KB
testcase_06 AC 20 ms
8,084 KB
testcase_07 AC 19 ms
8,176 KB
testcase_08 AC 24 ms
8,496 KB
testcase_09 AC 17 ms
8,200 KB
testcase_10 AC 20 ms
8,100 KB
testcase_11 AC 1,607 ms
62,008 KB
testcase_12 AC 1,424 ms
55,300 KB
testcase_13 AC 1,099 ms
46,656 KB
testcase_14 AC 1,158 ms
47,996 KB
testcase_15 AC 1,725 ms
64,224 KB
testcase_16 AC 1,631 ms
61,516 KB
testcase_17 AC 1,639 ms
62,628 KB
testcase_18 AC 1,653 ms
62,268 KB
testcase_19 AC 1,339 ms
62,892 KB
testcase_20 AC 1,480 ms
62,840 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