結果
問題 | No.1332 Range Nearest Query |
ユーザー |
👑 |
提出日時 | 2021-01-08 21:55:33 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,979 bytes |
コンパイル時間 | 972 ms |
コンパイル使用メモリ | 106,928 KB |
実行使用メモリ | 342,452 KB |
最終ジャッジ日時 | 2024-04-28 02:49:00 |
合計ジャッジ時間 | 6,804 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
65,408 KB |
testcase_01 | AC | 40 ms
59,888 KB |
testcase_02 | AC | 29 ms
59,908 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | AC | 2,213 ms
342,312 KB |
testcase_07 | AC | 1,953 ms
342,276 KB |
testcase_08 | AC | 1,933 ms
342,372 KB |
testcase_09 | AC | 1,929 ms
342,304 KB |
testcase_10 | AC | 1,906 ms
342,420 KB |
testcase_11 | AC | 1,923 ms
342,316 KB |
testcase_12 | AC | 1,953 ms
342,292 KB |
testcase_13 | AC | 1,969 ms
342,452 KB |
testcase_14 | AC | 1,971 ms
342,272 KB |
testcase_15 | AC | 2,025 ms
342,308 KB |
testcase_16 | TLE | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } constexpr int MAX_N = 300'010; constexpr int INF = 1'000'000'000; int N; int X[MAX_N]; int segN; set<int> seg[MAX_N * 4]; int main() { for (; ~scanf("%d", &N); ) { for (int i = 0; i < N; ++i) { scanf("%d", &X[i]); } for (segN = 1; segN < N; segN <<= 1) {} for (int u = 0; u < segN << 1; ++u) { seg[u].clear(); } for (int i = 0; i < N; ++i) { for (int u = segN + i; u; u >>= 1) { seg[u].insert(X[i]); } } int Q; scanf("%d", &Q); for (; Q--; ) { int l, r, x; scanf("%d%d%d", &l, &r, &x); --l; int ans = INF; auto doIt = [&](int u) { auto it = seg[u].lower_bound(x); if (it != seg[u].end()) { chmin(ans, *it - x); } if (it != seg[u].begin()) { --it; chmin(ans, x - *it); } }; for (int a = segN + l, b = segN + r; a < b; a >>= 1, b >>= 1) { if (a & 1) doIt(a++); if (b & 1) doIt(--b); } printf("%d\n", ans); } } return 0; }