結果
問題 |
No.1332 Range Nearest Query
|
ユーザー |
|
提出日時 | 2021-01-08 22:36:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,088 bytes |
コンパイル時間 | 1,335 ms |
コンパイル使用メモリ | 88,320 KB |
実行使用メモリ | 34,232 KB |
最終ジャッジ日時 | 2024-11-16 13:37:20 |
合計ジャッジ時間 | 121,547 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 TLE * 32 |
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 12 | main() | ^~~~
ソースコード
#include<iostream> #include<set> #include<vector> #include<algorithm> using namespace std; int N,Q; int X[3<<17]; set<int>S; int ans[1<<17]; const int B=500; vector<pair<pair<int,int>,pair<int,int> > >Qs; main() { cin>>N; for(int i=0;i<N;i++)cin>>X[i]; cin>>Q; for(int i=0;i<Q;i++) { int l,r,x;cin>>l>>r>>x; l--; Qs.push_back(make_pair(make_pair(l,r),make_pair(i,x))); } sort(Qs.begin(),Qs.end(),[](pair<pair<int,int>,pair<int,int> >a,pair<pair<int,int>,pair<int,int> >b) { if(a.first.first/B!=b.first.first/B)return a.first.first/B<b.first.first/B; else return a.first.second<b.first.second; }); int L=0,R=0; for(pair<pair<int,int>,pair<int,int> >q:Qs) { int l=q.first.first,r=q.first.second; while(L>l)S.insert(X[--L]); while(R<r)S.insert(X[R++]); while(L<l)S.erase(X[L++]); while(R>r)S.erase(X[--R]); int x=q.second.second; int id=q.second.first; ans[id]=1e9; auto it=S.lower_bound(x); if(it!=S.end())ans[id]=min(ans[id],*it-x); if(it!=S.begin()) { it--; ans[id]=min(ans[id],x-*it); } } for(int i=0;i<Q;i++)cout<<ans[i]<<endl; }