結果
| 問題 |
No.1332 Range Nearest Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 22:30:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,005 bytes |
| コンパイル時間 | 1,096 ms |
| コンパイル使用メモリ | 88,996 KB |
| 実行使用メモリ | 32,896 KB |
| 最終ジャッジ日時 | 2024-11-16 13:23:04 |
| 合計ジャッジ時間 | 113,085 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 1 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[(1<<17)/B+1];
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[l/B].push_back(make_pair(make_pair(r,l),make_pair(i,x)));
}
int L=0,R=0;
for(int i=0;i<=N/B;i++)
{
sort(Qs[i].begin(),Qs[i].end());
if(i%2)reverse(Qs[i].begin(),Qs[i].end());
for(pair<pair<int,int>,pair<int,int> >q:Qs[i])
{
int l=q.first.second,r=q.first.first;
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;
}