結果
問題 | No.877 Range ReLU Query |
ユーザー |
![]() |
提出日時 | 2019-09-06 22:59:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,362 bytes |
コンパイル時間 | 431 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 66,988 KB |
最終ジャッジ日時 | 2024-06-24 20:44:53 |
合計ジャッジ時間 | 20,036 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 19 TLE * 1 |
ソースコード
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)