結果

問題 No.1332 Range Nearest Query
ユーザー fumofumofunifumofumofuni
提出日時 2021-02-17 21:27:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,969 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 206,632 KB
実行使用メモリ 21,500 KB
最終ジャッジ日時 2023-10-12 07:35:18
合計ジャッジ時間 36,031 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
21,500 KB
testcase_01 AC 11 ms
10,836 KB
testcase_02 AC 11 ms
10,664 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 998 ms
10,664 KB
testcase_07 AC 998 ms
10,600 KB
testcase_08 AC 1,010 ms
10,652 KB
testcase_09 AC 996 ms
10,656 KB
testcase_10 AC 997 ms
10,712 KB
testcase_11 AC 998 ms
10,648 KB
testcase_12 AC 1,011 ms
10,752 KB
testcase_13 AC 999 ms
10,716 KB
testcase_14 AC 994 ms
10,688 KB
testcase_15 AC 996 ms
10,688 KB
testcase_16 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll near(vl &v,ll t){
    if(v.empty())return INF;
    auto p=lower_bound(all(v),t);
    ll ret=INF;
    if(p!=v.end()){
        chmin(ret,abs(t-*p));
    }
    if(p!=v.begin()){
        p--;
        chmin(ret,abs(t-*p));
    }
    return ret;
}

int main(){
    ll n;cin >> n;ll m=2400,K=150;
    vl X(m*K,INF);rep(i,n)cin >> X[i];
    vvl b(m);
    rep(i,X.size()){
        b[i/K].pb(X[i]);
    }
    rep(i,m)sort(all(b[i]));
    ll q;cin >> q;
    while(q--){
        ll x,y,t;cin >>x >> y >> t;x--;
        ll ans=INF;
        for (ll k = 0; k < m; ++k) {
            ll l = k * K, r = (k + 1) * K;
            if (r <= x || y <= l)
                continue;
            if (x <= l && r <= y) {
                chmin(ans,near(b[k],t));
            } 
            else {
                for (int i = max(x, l); i < min(y, r); ++i) {
                    chmin(ans,abs(t-X[i]));
                }
            }
        }
        cout << ans <<endl;
    }
}  
0