結果

問題 No.1332 Range Nearest Query
ユーザー fumofumofunifumofumofuni
提出日時 2021-01-08 23:19:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,020 bytes
コンパイル時間 2,321 ms
コンパイル使用メモリ 205,820 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-04-28 05:34:58
合計ジャッジ時間 42,237 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
10,112 KB
testcase_01 AC 6 ms
9,984 KB
testcase_02 AC 6 ms
9,984 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
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 WA -
testcase_27 AC 1,132 ms
10,112 KB
testcase_28 AC 236 ms
10,112 KB
testcase_29 AC 237 ms
9,984 KB
testcase_30 AC 231 ms
10,112 KB
testcase_31 AC 234 ms
10,112 KB
testcase_32 AC 236 ms
10,240 KB
testcase_33 AC 237 ms
10,112 KB
testcase_34 AC 234 ms
10,112 KB
testcase_35 AC 234 ms
10,112 KB
testcase_36 AC 228 ms
9,984 KB
testcase_37 AC 233 ms
10,112 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=560;
    vl X(m*K,INF);rep(i,n)cin >> X[i];
    vvl b(m);
    rep(i,X.size()){
        b[i/K].pb(X[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