Submission #892976

# Submission time Handle Problem Language Result Execution time Memory
892976 2023-12-26T09:31:33 Z alexander707070 Bitaro's travel (JOI23_travel) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#define MAXN 200007
using namespace std;

int n,t[MAXN],q,s;

long long solve(int s,int from,int to){
    int l=from,r=to;
    long long res=0;

    while(l!=0 or r!=n+1){
        if(l>=1 and s-t[l]<=t[r]-s){
            int ll=0,rr=l,mid;
            while(ll+1<rr){
                mid=(ll+rr)/2;
                if(s-t[mid]<2*(s-t[l])){
                    rr=mid;
                }else{
                    ll=mid;
                }
            }
            res+=s-t[rr];
            l=rr-1; s=t[rr];
        }else if(r<=n and t[r]-s<=s-t[l]){
            int ll=r,rr=n+1,mid;
            while(ll+1<rr){
                mid=(ll+rr)/2;
                if(t[mid]-s<2*(t[r]-s)){
                    ll=mid;
                }else{
                    rr=mid;
                }
            }
            res+=t[ll]-s;
            r=ll+1; s=t[ll];
        }else{
            exit(0);
        }
    }

    return res;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    t[n+1]=2*t[n]+1;

    cin>>q;
    for(int i=1;i<=q;i++){
        cin>>s;

        int l=0,r=n+1,mid;
        while(l+1<r){
            mid=(l+r)/2;
            if(t[mid]<=s){
                l=mid;
            }else{
                r=mid;
            }
        }

        cout<<solve(s,l,l+1)<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -