結果

問題 No.1332 Range Nearest Query
ユーザー fumofumofunifumofumofuni
提出日時 2021-01-08 23:23:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,049 bytes
コンパイル時間 2,292 ms
コンパイル使用メモリ 209,840 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2024-04-28 05:41:34
合計ジャッジ時間 52,106 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,856 KB
testcase_01 AC 10 ms
9,984 KB
testcase_02 AC 9 ms
9,984 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 587 ms
9,984 KB
testcase_07 AC 595 ms
9,984 KB
testcase_08 AC 592 ms
9,984 KB
testcase_09 AC 594 ms
10,112 KB
testcase_10 AC 589 ms
9,984 KB
testcase_11 AC 591 ms
9,952 KB
testcase_12 AC 592 ms
9,984 KB
testcase_13 AC 598 ms
9,984 KB
testcase_14 AC 584 ms
9,976 KB
testcase_15 AC 590 ms
9,984 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1,322 ms
9,984 KB
testcase_27 AC 1,239 ms
9,984 KB
testcase_28 AC 282 ms
9,984 KB
testcase_29 AC 279 ms
10,036 KB
testcase_30 AC 282 ms
9,948 KB
testcase_31 AC 277 ms
9,984 KB
testcase_32 AC 286 ms
10,112 KB
testcase_33 AC 284 ms
10,036 KB
testcase_34 AC 283 ms
10,112 KB
testcase_35 AC 278 ms
9,984 KB
testcase_36 AC 284 ms
9,960 KB
testcase_37 AC 282 ms
9,984 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
権限があれば一括ダウンロードができます

ソースコード

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));
        p++;
        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=550,K=550;
    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