結果
| 問題 |
No.1332 Range Nearest Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 23:19:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,128 bytes |
| コンパイル時間 | 759 ms |
| コンパイル使用メモリ | 67,840 KB |
| 実行使用メモリ | 36,032 KB |
| 最終ジャッジ日時 | 2024-11-16 18:00:15 |
| 合計ジャッジ時間 | 115,713 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 TLE * 32 |
コンパイルメッセージ
main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main()
| ^~~~
ソースコード
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
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()
{
scanf("%d",&N);
for(int i=0;i<N;i++)scanf("%d",&X[i]);
scanf("%d",&Q);
for(int i=0;i<Q;i++)
{
int l,r,x;
scanf("%d%d%d",&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++)printf("%d\n",ans[i]);
}