結果
問題 | No.1332 Range Nearest Query |
ユーザー | kappybar |
提出日時 | 2021-01-08 23:32:52 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,744 bytes |
コンパイル時間 | 2,015 ms |
コンパイル使用メモリ | 177,300 KB |
実行使用メモリ | 184,244 KB |
最終ジャッジ日時 | 2024-04-28 05:50:19 |
合計ジャッジ時間 | 7,589 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
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 <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; struct query{ int l,r,y; }; int main(){ int n; cin >> n; vector<int> x(n); rep(i,n) cin >> x[i]; int q; cin >> q; vector<int> l(q),r(q),y(q),qi(q); rep(i,q){ cin >> l[i] >> r[i] >> y[i]; --l[i]; qi[i] = i; } int sq = sqrt(n); sort(qi.begin(),qi.end(),[&](int i,int j){ if(l[i] / sq != l[j] / sq) return l[i] < l[j]; if((l[i] / sq)%2 == 1) return r[i] > r[j]; return r[i] < r[j]; }); multiset<int> st; auto add = [&](int id){ if(id<0||n<=id) return; st.insert(x[id]); }; auto del = [&](int id){ if(id<0||n<=id) return; st.erase(st.find(x[id])); }; vector<int> queryans(q); int nl = 0,nr = 0; for(int i:qi){ while(nl > l[i]) --nl,add(nl); while(nr < r[i]) add(nr),++nr; while(nl < l[i]) del(nl),++nl; while(nr > r[i]) --nr,del(nr); auto it = st.lower_bound(y[i]); int ans = INF; if(it == st.end()){ ans = abs(y[i]-*(--it)); }else if(it == st.begin()){ ans = abs(y[i]-*it); }else{ ans = abs(y[i]-*it); chmin(ans,abs(y[i]-*(--it))); } queryans[i] = ans; } rep(i,q) printf("%d\n",queryans[i]); return 0; return 0; }