結果
問題 | No.1332 Range Nearest Query |
ユーザー | fastmath |
提出日時 | 2021-01-08 21:59:31 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 794 ms / 2,500 ms |
コード長 | 2,584 bytes |
コンパイル時間 | 2,455 ms |
コンパイル使用メモリ | 207,808 KB |
実行使用メモリ | 109,952 KB |
最終ジャッジ日時 | 2024-11-16 11:39:35 |
合計ジャッジ時間 | 25,181 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 21 ms
31,488 KB |
testcase_01 | AC | 23 ms
31,488 KB |
testcase_02 | AC | 23 ms
31,616 KB |
testcase_03 | AC | 649 ms
83,680 KB |
testcase_04 | AC | 651 ms
83,680 KB |
testcase_05 | AC | 635 ms
83,680 KB |
testcase_06 | AC | 372 ms
109,948 KB |
testcase_07 | AC | 366 ms
109,820 KB |
testcase_08 | AC | 364 ms
109,804 KB |
testcase_09 | AC | 365 ms
109,820 KB |
testcase_10 | AC | 369 ms
109,948 KB |
testcase_11 | AC | 362 ms
109,952 KB |
testcase_12 | AC | 364 ms
109,948 KB |
testcase_13 | AC | 381 ms
109,952 KB |
testcase_14 | AC | 366 ms
109,824 KB |
testcase_15 | AC | 362 ms
109,952 KB |
testcase_16 | AC | 738 ms
109,824 KB |
testcase_17 | AC | 741 ms
109,820 KB |
testcase_18 | AC | 760 ms
109,824 KB |
testcase_19 | AC | 781 ms
109,824 KB |
testcase_20 | AC | 786 ms
109,952 KB |
testcase_21 | AC | 794 ms
109,952 KB |
testcase_22 | AC | 778 ms
109,820 KB |
testcase_23 | AC | 762 ms
109,824 KB |
testcase_24 | AC | 757 ms
109,696 KB |
testcase_25 | AC | 761 ms
109,824 KB |
testcase_26 | AC | 277 ms
109,952 KB |
testcase_27 | AC | 267 ms
109,952 KB |
testcase_28 | AC | 46 ms
31,488 KB |
testcase_29 | AC | 48 ms
31,488 KB |
testcase_30 | AC | 49 ms
31,616 KB |
testcase_31 | AC | 44 ms
31,488 KB |
testcase_32 | AC | 48 ms
31,616 KB |
testcase_33 | AC | 48 ms
31,616 KB |
testcase_34 | AC | 44 ms
31,488 KB |
testcase_35 | AC | 45 ms
31,488 KB |
testcase_36 | AC | 45 ms
31,488 KB |
testcase_37 | AC | 48 ms
31,488 KB |
testcase_38 | AC | 474 ms
70,032 KB |
testcase_39 | AC | 151 ms
33,664 KB |
testcase_40 | AC | 753 ms
108,168 KB |
testcase_41 | AC | 289 ms
42,368 KB |
testcase_42 | AC | 472 ms
68,364 KB |
testcase_43 | AC | 366 ms
52,232 KB |
testcase_44 | AC | 605 ms
79,832 KB |
testcase_45 | AC | 570 ms
76,780 KB |
testcase_46 | AC | 430 ms
56,280 KB |
testcase_47 | AC | 534 ms
73,060 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define x first #define y second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; #define FOR(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define trav(a, x) for (auto& a : x) using vi = vector<int>; template <typename T> std::ostream& operator <<(std::ostream& output, const pair <T, T> & data) { output << "(" << data.x << "," << data.y << ")"; return output; } template <typename T> std::ostream& operator <<(std::ostream& output, const std::vector<T>& data) { for (const T& x : data) output << x << " "; return output; } //ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up //ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT> void re(V<T>& x) { trav(a, x) cin >> a; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int N = 3e5+7, INF = 1e9+7; int n, q; int a[N]; vi t[N << 2]; void build(int v, int tl, int tr) { if (tl == tr) { t[v] = {a[tl]}; return; } int tm = (tl + tr) >> 1; build(v * 2 + 1, tl, tm); build(v * 2 + 2, tm + 1, tr); trav (x, t[v * 2 + 1]) t[v].app(x); trav (x, t[v * 2 + 2]) t[v].app(x); sort(all(t[v])); } int get(int v, int tl, int tr, int l, int r, int x) { if (tr < l || r < tl) return INF; if (l <= tl && tr <= r) { auto u = lower_bound(all(t[v]), x); int ans = INF; if (u != t[v].begin()) ckmin(ans, abs(*prev(u) - x)); if (u != t[v].end()) ckmin(ans, abs(*u - x)); return ans; } int tm = (tl + tr) >> 1; return min(get(v * 2 + 1, tl, tm, l, r, x) , get(v * 2 + 2, tm + 1, tr, l, r, x)); } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif cin >> n; FOR (i, n) cin >> a[i]; build(0, 0, n - 1); cin >> q; while (q--) { int l, r, x; cin >> l >> r >> x; cout << get(0, 0, n - 1, l - 1, r - 1, x) << endl; } }