Submission #551429

#TimeUsernameProblemLanguageResultExecution timeMemory
551429Ronin13Intercastellar (JOI22_ho_t1)C++14
100 / 100
83 ms7692 KiB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;

ll get(ll x, ll k){
    if(x & 1) return x;
    ll y = x / 2;
    ll cnt = y & -y;
    if(cnt < k)return get(x / 2, k - cnt);
    return get(x / 2, k);
}

ll lsb(ll x){
    return x & -x;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    ll a[n + 1];
    for(int i = 1; i <= n; i++){
         cin >> a[i];
    }
    int q; cin >> q;
    ll cnt = 0;
    int ind = 1;
    for(int i = 1; i <= q; i++){
        ll x; cin >> x;
        while(cnt + lsb(a[ind]) < x)ind++, cnt += lsb(a[ind - 1]);
        cout << get(a[ind], x - cnt) << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...