結果

問題 No.877 Range ReLU Query
ユーザー 双六双六
提出日時 2020-08-04 00:56:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 574 ms / 2,000 ms
コード長 2,014 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 82,976 KB
実行使用メモリ 109,092 KB
最終ジャッジ日時 2024-04-25 22:23:19
合計ジャッジ時間 7,595 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,988 KB
testcase_01 AC 78 ms
77,608 KB
testcase_02 AC 64 ms
74,472 KB
testcase_03 AC 81 ms
77,420 KB
testcase_04 AC 53 ms
64,296 KB
testcase_05 AC 58 ms
69,528 KB
testcase_06 AC 61 ms
70,656 KB
testcase_07 AC 57 ms
67,888 KB
testcase_08 AC 81 ms
77,128 KB
testcase_09 AC 48 ms
65,116 KB
testcase_10 AC 63 ms
72,348 KB
testcase_11 AC 531 ms
105,144 KB
testcase_12 AC 500 ms
104,776 KB
testcase_13 AC 403 ms
96,548 KB
testcase_14 AC 396 ms
97,052 KB
testcase_15 AC 572 ms
105,392 KB
testcase_16 AC 549 ms
103,540 KB
testcase_17 AC 574 ms
104,468 KB
testcase_18 AC 545 ms
104,064 KB
testcase_19 AC 474 ms
108,140 KB
testcase_20 AC 554 ms
109,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N = N
		self.N0 = 2 ** (N - 1).bit_length()
		self.initVal = 0
		self.data = [self.initVal] * (2 * self.N0)

	# 区間クエリの種類
	def calc(self, a, b):
		return a + b

	# セグメント木の中身をリストAで初期化
	def initialize(self, A):
		for i in range(self.N):
			self.data[self.N0 - 1 + i] = A[i]
		for i in range(self.N0 - 2, -1, -1):
			self.data[i] = self.calc(self.data[2 * i + 1], self.data[2 * i + 2])

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.calc(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の演算値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = self.initVal
		while L < R:
			if R & 1:
				R -= 1
				m = self.calc(m, self.data[R - 1])
			if L & 1:
				m = self.calc(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

#処理内容
def main():
	N, Q = getlist()
	A = getlist()
	Alist = [[A[i], i] for i in range(N)]
	query = []
	Seg01 = SegmentTree(N)
	Segval = SegmentTree(N)
	Seg01.initialize([1] * N)
	Segval.initialize(A)
	ans = [0] * Q
	for i in range(Q):
		q = getlist()
		l = q[1]; r = q[2]; x = q[3]
		l -= 1; r -= 1
		query.append([x, l, r, i])
	
	Alist.sort(key=lambda x: x[0])
	query.sort(key=lambda x: x[0])
	i = 0; j = 0
	while i < N and j < Q:
		Ai, itr = Alist[i]
		x, l, r, ansitr = query[j]
		if Ai < x:
			Seg01.update(itr, 0)
			Segval.update(itr, 0)
			i += 1
		else:
			anspre = Segval.query(l, r) - x * Seg01.query(l, r)
			ans[ansitr] = anspre
			j += 1

	for t in range(j, Q):
		x, l, r, ansitr = query[t]
		ans[ansitr] = 0

	for i in range(Q):
		print(ans[i])

if __name__ == '__main__':
	main()
0