結果
問題 | No.1982 [Cherry 4th Tune B] 絶険 |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:48:47 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,967 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 567,276 KB |
最終ジャッジ日時 | 2025-03-26 15:49:48 |
合計ジャッジ時間 | 11,582 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 5 MLE * 1 -- * 29 |
ソースコード
import sysclass Node:__slots__ = ['left', 'right', 'sum']def __init__(self, left=None, right=None, sum=0):self.left = leftself.right = rightself.sum = sumdef main():import syssys.setrecursionlimit(1 << 25)input = sys.stdin.readdata = input().split()ptr = 0N = int(data[ptr])ptr +=1K = int(data[ptr])ptr +=1Q = int(data[ptr])ptr +=1operations = []for _ in range(K):L = int(data[ptr])ptr +=1R = int(data[ptr])ptr +=1C = int(data[ptr])ptr +=1H = int(data[ptr])ptr +=1operations.append( (L, R, C, H) )# Persistent segment tree setuproots = [None]*(K+1) # roots[0] is the initial empty treeroots[0] = Node()current_root = roots[0]for j in range(1, K+1):L, R, C, H = operations[j-1]# Function to apply the range add, creating a new rootdef add(node, a, b):if b < L or a > R:return nodenew_node = Node()if node is not None:new_node.left = node.leftnew_node.right = node.rightnew_node.sum = node.sumelse:new_node.sum = 0if L <= a and b <= R:new_node.sum += Hreturn new_nodemid = (a + b) // 2new_node.left = add(new_node.left, a, mid) if new_node.left else add(Node(), a, mid)new_node.right = add(new_node.right, mid+1, b) if new_node.right else add(Node(), mid+1, b)return new_nodenew_root = add(current_root, 1, N)roots[j] = new_rootcurrent_root = new_root# Query functiondef query(root, a, b, i):if not root:return 0res = root.sumif a == b:return resmid = (a + b) // 2if i <= mid:res += query(root.left, a, mid, i)else:res += query(root.right, mid+1, b, i)return res# Process queriesoutput = []for _ in range(Q):I = int(data[ptr])ptr +=1X = int(data[ptr])ptr +=1x = X - 0.5if K ==0:output.append(-1)continuesum_total = query(roots[K], 1, N, I)if sum_total < x:output.append(-1)continue# Binary search to find the earliest jlow = 1high = Kanswer = Kwhile low <= high:mid = (low + high) //2s = query(roots[mid], 1, N, I)if s >= x:answer = midhigh = mid -1else:low = mid +1# Get the colorL_j, R_j, C_j, H_j = operations[answer-1]output.append(C_j)print('\n'.join(map(str, output)))if __name__ == "__main__":main()