Submission #1242146

#TimeUsernameProblemLanguageResultExecution timeMemory
1242146GeforgsMarathon Race 2 (JOI24_ho_t3)C++20
7 / 100
0 ms328 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
#define ll long long
#define ld long double
#define inf (ll)(2*1e18)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define endl "\n"
using namespace std;

void solve(){
    ll n, q, l, i, x, y, time, res, pos1, pos2;
    cin>>n>>l;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a);
    for(i=1;i<n;++i){
        b[i] = b[i-1] + (a[i] - a[i-1])*(i+1);
    }
    for(i=n-2;i>=0;--i){
        c[i] = c[i+1] + (a[i+1] - a[i])*(n - i);
    }
    cin>>q;
    for(i=0;i<q;++i){
        cin>>x>>y>>time;
        pos1 = lower_bound(a.begin(), a.end(), y) - a.begin() - 1;
        pos2 = lower_bound(a.begin(), a.end(), y) - a.begin();
        if(pos1 == -1){
            res = c[0] + (n+1)*(a[0] - y) + abs(x - a.back());
        }else if(pos2 == n){
            res = b.back() + (n+1)*(y - a.back()) + abs(x - a.front());
        }else{
            res = b[pos1] + c[pos2] + min((n+1)*(y - a[pos1]) + abs(x - a.back()) + (a[pos2] - a.front() + a[pos1] - a.front())*(n - pos2 + 1), (n+1)*(a[pos2] - y) + abs(x - a.front()) + (a.back() - a[pos2] + a.back() - a[pos1])*(pos1 + 2));
        }
        res += n;
        if(res <= time){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(time(nullptr));
    ll t=1;
//    cin>>t;
    for(;t>0;--t){
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...