結果
問題 | No.1332 Range Nearest Query |
ユーザー | k |
提出日時 | 2021-04-21 00:58:51 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,151 bytes |
コンパイル時間 | 3,961 ms |
コンパイル使用メモリ | 203,904 KB |
実行使用メモリ | 556,532 KB |
最終ジャッジ日時 | 2023-09-17 09:14:06 |
合計ジャッジ時間 | 50,328 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 231 ms
284,648 KB |
testcase_01 | AC | 205 ms
284,664 KB |
testcase_02 | AC | 170 ms
284,660 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | MLE | - |
testcase_07 | MLE | - |
testcase_08 | MLE | - |
testcase_09 | MLE | - |
testcase_10 | MLE | - |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
testcase_15 | MLE | - |
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 | MLE | - |
testcase_27 | MLE | - |
testcase_28 | AC | 311 ms
284,584 KB |
testcase_29 | AC | 316 ms
284,564 KB |
testcase_30 | AC | 312 ms
284,696 KB |
testcase_31 | AC | 310 ms
284,656 KB |
testcase_32 | AC | 316 ms
284,632 KB |
testcase_33 | AC | 313 ms
284,696 KB |
testcase_34 | AC | 309 ms
284,916 KB |
testcase_35 | AC | 311 ms
284,868 KB |
testcase_36 | AC | 313 ms
284,572 KB |
testcase_37 | AC | 314 ms
284,668 KB |
testcase_38 | AC | 2,022 ms
416,024 KB |
testcase_39 | AC | 699 ms
291,864 KB |
testcase_40 | TLE | - |
testcase_41 | AC | 1,090 ms
329,016 KB |
testcase_42 | AC | 1,825 ms
408,228 KB |
testcase_43 | AC | 1,509 ms
360,512 KB |
testcase_44 | AC | 2,421 ms
484,092 KB |
testcase_45 | AC | 2,195 ms
460,508 KB |
testcase_46 | AC | 1,683 ms
393,980 KB |
testcase_47 | TLE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; const int INF = 1<<30; set<int> t[6000000]; void build(const vector<int> &x, int k, int l, int r) { if (l < r) { for (int i = l; i < r; i++) t[k].insert(x[i]); if (r - l >= 2) { int m = (l + r) / 2; build(x, 2 * k + 1, l, m); build(x, 2 * k + 2, m, r); } } } int query(int k, int l, int r, int a, int b, int y) { if (b <= l || r <= a) return INF; if (a <= l && r <= b) { int ret = INF; auto itr = t[k].lower_bound(y); if (itr != t[k].end()) ret = min(ret, abs(*itr - y)); if (itr != t[k].begin()) { --itr; ret = min(ret, abs(*itr - y)); } return ret; } int mi = (l + r) / 2; return min(query(2 * k + 1, l, mi, a, b, y), query(2 * k + 2, mi, r, a, b, y)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> x(n); for (int i = 0; i < n; i++) cin >> x[i]; build(x, 0, 0, n); int q; cin >> q; for (int i = 0; i < q; i++) { int l, r, y; cin >> l >> r >> y; --l; cout << query(0, 0, n, l, r, y) << endl; } return 0; }