제출 #1180012

#제출 시각아이디문제언어결과실행 시간메모리
1180012bbartekIntercastellar (JOI22_ho_t1)C++20
100 / 100
46 ms5408 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define st first
#define nd second
#define pb push_back

const int maxn = 2e5+7;

int liczby[maxn];
int koncowy[maxn];
ll sumy[maxn];

int binsearchh(int pocz,int kon,ll val){
    int sro;
    while(pocz < kon){
        sro = (pocz+kon)/2;
        if(sumy[sro] < val){
            pocz = sro+1;
        }
        else{
            kon = sro;
        }
    }
    return pocz;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;

    ll a,mnoznik;
    for(int i=1;i<=n;i++){
        cin>>a;
        mnoznik = 1;
        liczby[i] = a;
        sumy[i] = sumy[i-1];
        while(true){
            if(a%2 == 1){
                sumy[i] += mnoznik;
                koncowy[i] = a;
                break;
            }
            else{
                mnoznik *= 2;
                a/=2;
            }
        }
    }

    ll q,x;
    cin>>q;
    while(q--){
        cin>>a;
        x = binsearchh(0,n,a);
        cout<<koncowy[x]<<"\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...