結果
問題 | No.1332 Range Nearest Query |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2021-01-08 22:55:47 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,464 bytes |
コンパイル時間 | 618 ms |
コンパイル使用メモリ | 87,040 KB |
実行使用メモリ | 436,184 KB |
最終ジャッジ日時 | 2023-08-10 11:15:23 |
合計ジャッジ時間 | 84,224 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 70 ms
71,148 KB |
testcase_01 | AC | 71 ms
71,424 KB |
testcase_02 | AC | 70 ms
70,956 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | AC | 1,721 ms
433,348 KB |
testcase_07 | AC | 1,769 ms
433,232 KB |
testcase_08 | AC | 1,743 ms
434,336 KB |
testcase_09 | AC | 1,740 ms
433,164 KB |
testcase_10 | AC | 1,765 ms
433,172 KB |
testcase_11 | AC | 1,699 ms
433,480 KB |
testcase_12 | AC | 1,712 ms
434,128 KB |
testcase_13 | AC | 1,744 ms
433,292 KB |
testcase_14 | AC | 1,739 ms
433,480 KB |
testcase_15 | AC | 1,719 ms
433,340 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | AC | 1,162 ms
436,184 KB |
testcase_27 | AC | 1,143 ms
426,404 KB |
testcase_28 | AC | 275 ms
97,600 KB |
testcase_29 | AC | 297 ms
97,756 KB |
testcase_30 | AC | 355 ms
99,872 KB |
testcase_31 | AC | 204 ms
95,148 KB |
testcase_32 | AC | 377 ms
100,308 KB |
testcase_33 | AC | 398 ms
100,040 KB |
testcase_34 | AC | 243 ms
95,116 KB |
testcase_35 | AC | 310 ms
97,784 KB |
testcase_36 | AC | 293 ms
96,760 KB |
testcase_37 | AC | 318 ms
99,080 KB |
testcase_38 | AC | 2,046 ms
256,436 KB |
testcase_39 | AC | 990 ms
110,904 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 1,420 ms
138,128 KB |
testcase_42 | AC | 2,010 ms
250,664 KB |
testcase_43 | AC | 1,726 ms
172,932 KB |
testcase_44 | AC | 2,317 ms
284,396 KB |
testcase_45 | AC | 2,242 ms
278,316 KB |
testcase_46 | AC | 1,923 ms
185,200 KB |
testcase_47 | AC | 2,164 ms
262,312 KB |
ソースコード
import sys input = sys.stdin.readline from bisect import bisect_left class SegTree: """ define what you want to do with 0 index, ex) size = tree_size, func = min or max, sta = default_value """ def __init__(self,size): self.n = size self.size = 1 << size.bit_length() self.tree = [[-10**10,10**10]]*(2*self.size) def build(self, list): """ set list and update tree""" for i,x in enumerate(list,self.size): self.tree[i] = sorted(self.tree[i]+[x]) for i in range(self.size-1,0,-1): self.tree[i] = sorted(self.tree[i<<1]+self.tree[i<<1 | 1]) def get(self,l,r,x): """ take the value of [l r) with func (min or max)""" l += self.size r += self.size res = 10**10 while l < r: if l & 1: t = bisect_left(self.tree[l],x) res = min(res,x-self.tree[l][t-1],self.tree[l][t]-x) l += 1 if r & 1: t = bisect_left(self.tree[r-1],x) res = min(res,x-self.tree[r-1][t-1],self.tree[r-1][t]-x) l >>= 1 r >>= 1 if res == 0: return res return res n = int(input()) X = list(map(int,input().split())) Q = int(input()) q = [tuple(map(int,input().split())) for i in range(Q)] seg = SegTree(n) seg.build(X) ans = [] for l,r,x in q: ans.append(seg.get(l-1,r,x)) print(*ans,sep="\n")