結果
| 問題 |
No.1332 Range Nearest Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 21:52:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,568 bytes |
| コンパイル時間 | 1,186 ms |
| コンパイル使用メモリ | 87,564 KB |
| 実行使用メモリ | 135,424 KB |
| 最終ジャッジ日時 | 2024-11-16 11:20:07 |
| 合計ジャッジ時間 | 104,152 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 TLE * 22 |
コンパイルメッセージ
a.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
using namespace std;
#line 1 "/home/kotatsugame/library/datastructure/rangefreq.cpp"
#include<vector>
#line 3 "/home/kotatsugame/library/datastructure/rangefreq.cpp"
template<typename T>
struct rangefreq{
int n;
vector<vector<T> >dat;
rangefreq(const vector<T>&v={})
{
n=1;
while(n<v.size())n<<=1;
dat.assign(2*n-1,{});
for(int i=0;i<v.size();i++)dat[i+n-1].push_back(v[i]);
for(int i=n-2;i>=0;i--)
{
dat[i].resize(dat[i*2+1].size()+dat[i*2+2].size());
merge(dat[i*2+1].begin(),dat[i*2+1].end(),
dat[i*2+2].begin(),dat[i*2+2].end(),
dat[i].begin()
);
}
}
int query(int a,int b,T x,int k=0,int l=0,int r=-1)const//[a,b) count(*<x)
{
if(r<0)r=n;
if(b<=l||r<=a)return 0;
else if(a<=l&&r<=b)return lower_bound(dat[k].begin(),dat[k].end(),x)-dat[k].begin();
else return query(a,b,x,k*2+1,l,(l+r)/2)+query(a,b,x,k*2+2,(l+r)/2,r);
}
};
#line 5 "a.cpp"
int N,X[3<<17];
main()
{
cin>>N;
for(int i=0;i<N;i++)cin>>X[i];
rangefreq<int>P(vector<int>(X,X+N));
int Q;cin>>Q;
for(;Q--;)
{
int l,r,x;cin>>l>>r>>x;l--;
int ans=1e9;
{
int cnt=P.query(l,r,x+1);
if(cnt>0)
{
int L=1,R=x+1;
while(R-L>1)
{
int mid=(L+R)/2;
if(P.query(l,r,mid)<cnt)L=mid;
else R=mid;
}
ans=min(ans,x-L);
}
}
{
int cnt=r-l-P.query(l,r,x);
if(cnt>0)
{
int L=x,R=1e9+1;
while(R-L>1)
{
int mid=(L+R)/2;
if(r-l-P.query(l,r,mid)<cnt)R=mid;
else L=mid;
}
ans=min(ans,L-x);
}
}
cout<<ans<<endl;
}
}