제출 #780480

#제출 시각아이디문제언어결과실행 시간메모리
780480antonIntercastellar (JOI22_ho_t1)C++17
100 / 100
399 ms10680 KiB
#include<bits/stdc++.h>

using namespace std;
#define int long long


vector<int> a;
vector<int> f;
vector<int> s;
signed main(){
    int n;
    cin>>n;
    a.resize(n);
    s.resize(n);
    f.resize(n);

    for(int i = 0; i<n; i++){
        cin>>a[i];
        f[i] = a[i];
        s[i] = 1LL;
        
        while(f[i]%2 ==0){
            f[i] = f[i]/2LL;
            s[i] = s[i]*2LL;
        }
        if(i!=0){
            s[i]+=s[i-1];
        }
    }

    int q;
    cin>>q;

    for(int i = 0; i<q; i++){
        int x;
        cin>>x;
        int id= 0;

        if(s[0]>=x){
            cout<<f[0]<<endl;
            continue;
        }
        for(int step = (1LL<<20LL); step>=1; step/=2LL){
            if(id+ step<n){
                if(s[id+step]<x){
                    id+=step;
                }
            }
        }

        cout<<f[id+1]<<endl;

    }


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...