結果
問題 | No.1332 Range Nearest Query |
ユーザー | penguinman |
提出日時 | 2020-11-23 04:43:13 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,353 bytes |
コンパイル時間 | 306 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 166,072 KB |
最終ジャッジ日時 | 2024-07-23 17:03:52 |
合計ジャッジ時間 | 39,405 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
ソースコード
# Refernce: https://atcoder.jp/contests/practice2/submissions/16814531 class SegTree(): def __init__(self, a, func, idem): # the number of nodes is 2n - 1 self.n = 1 << len(a).bit_length() self.size = len(a) self.func = func self.idem = idem # Identity element self.node = [idem] * (2 * self.n - 1) for i in range(len(a) + self.n - 2, -1, -1): if i >= self.n - 1: self.node[i] = a[i - self.n + 1] else: self.node[i] = self.func(self.node[2 * i + 1], self.node[2 * i + 2]) def get(self, x): return self.node[x + self.n - 1] def set(self, x, val): x += self.n - 1 self.node[x] = val while x > 0: x = (x - 1) >> 1 self.node[x] = self.func(self.node[2*x+1], self.node[2*x+2]) return def prod(self, l, r): L, R = l + self.n, r + self.n s_l, s_r = self.idem, self.idem while L < R: if R & 1: R -= 1 s_r = self.func(self.node[R-1], s_r) if L & 1: s_l = s_l = self.func(s_l, self.node[L-1]) L += 1 L >>= 1 R >>= 1 return self.func(s_l, s_r) def max_right(self, l, val): if l == self.size: return self.size L = l + self.n s = self.idem while 1: while L % 2 == 0: L >>= 1 if not val(self.func(s, self.node[L - 1])): while L < self.n: L <<= 1 if val(self.func(s, self.node[L-1])): s = self.func(s, self.node[L-1]) L += 1 return L - self.n s = self.func(s, self.node[L - 1]) L += 1 if (L & -L) == L: return self.size def min_left(self, r, val): if r == 0: return 0 R = r + self.n s = self.idem while True: R -= 1 while R > 1 and R % 2: R >>= 1 if not val(self.func(self.node[R - 1], s)): while R < self.n: R = (R << 1) + 1 if val(self.func(self.node[R - 1], s)): s = self.func(self.node[R - 1], s) R -= 1 return R + 1 - self.n s = self.func(self.node[R - 1], s) if (R & -R) == R: return 0 import sys input=sys.stdin.readline import bisect inf=int(1e9) N=int(input()) X=list(map(int,input().split())) Q=int(input()) #data[i][1] が正ならクエリ、そうでなければ座標 data=[[]] left=[] right=[] for i in range(N): data.append([X[i],-i]) for i in range(Q): l,r,x=map(int, input().split()) left.append(l) right.append(r) data.append([x,i+1]) ans=[inf]*Q A=[-inf]*(N+Q) seg=SegTree(A,max,-inf) for _ in range(2): data=sorted(data) for i in range(N+Q): if data[i][1]<=0: seg.set(-data[i][1],data[i][0]) else: index=data[i][1]-1 ans[index]=min(ans[index],data[i][0]-seg.prod(left[index]-1,right[index])) for i in range(N+Q): data[i][0]=inf-data[i][0] for i in range(Q): print(ans[i])