結果

問題 No.1332 Range Nearest Query
ユーザー fumofumofunifumofumofuni
提出日時 2021-02-17 21:28:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,038 ms / 2,500 ms
コード長 1,969 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 207,640 KB
実行使用メモリ 9,300 KB
最終ジャッジ日時 2023-10-12 07:36:57
合計ジャッジ時間 37,122 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
9,172 KB
testcase_01 AC 9 ms
9,280 KB
testcase_02 AC 9 ms
9,116 KB
testcase_03 AC 950 ms
9,020 KB
testcase_04 AC 963 ms
9,148 KB
testcase_05 AC 966 ms
9,244 KB
testcase_06 AC 605 ms
8,948 KB
testcase_07 AC 615 ms
9,112 KB
testcase_08 AC 606 ms
9,088 KB
testcase_09 AC 614 ms
8,992 KB
testcase_10 AC 607 ms
9,092 KB
testcase_11 AC 611 ms
8,984 KB
testcase_12 AC 607 ms
9,064 KB
testcase_13 AC 608 ms
9,008 KB
testcase_14 AC 610 ms
8,984 KB
testcase_15 AC 605 ms
9,120 KB
testcase_16 AC 1,024 ms
9,024 KB
testcase_17 AC 1,022 ms
9,108 KB
testcase_18 AC 1,038 ms
9,108 KB
testcase_19 AC 1,035 ms
9,164 KB
testcase_20 AC 1,028 ms
9,008 KB
testcase_21 AC 1,017 ms
9,036 KB
testcase_22 AC 1,032 ms
9,088 KB
testcase_23 AC 1,027 ms
9,284 KB
testcase_24 AC 1,024 ms
9,040 KB
testcase_25 AC 1,024 ms
9,068 KB
testcase_26 AC 596 ms
9,060 KB
testcase_27 AC 540 ms
8,988 KB
testcase_28 AC 222 ms
9,056 KB
testcase_29 AC 218 ms
9,016 KB
testcase_30 AC 216 ms
9,012 KB
testcase_31 AC 215 ms
9,108 KB
testcase_32 AC 226 ms
9,020 KB
testcase_33 AC 221 ms
9,180 KB
testcase_34 AC 219 ms
9,300 KB
testcase_35 AC 216 ms
9,004 KB
testcase_36 AC 215 ms
9,012 KB
testcase_37 AC 216 ms
9,100 KB
testcase_38 AC 767 ms
9,164 KB
testcase_39 AC 455 ms
9,012 KB
testcase_40 AC 1,014 ms
9,020 KB
testcase_41 AC 569 ms
9,172 KB
testcase_42 AC 748 ms
9,036 KB
testcase_43 AC 644 ms
9,036 KB
testcase_44 AC 894 ms
9,248 KB
testcase_45 AC 857 ms
9,172 KB
testcase_46 AC 719 ms
9,108 KB
testcase_47 AC 816 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

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=150,K=2400;
    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