Submission #1156532

#TimeUsernameProblemLanguageResultExecution timeMemory
1156532NurislamIntercastellar (JOI22_ho_t1)C++20
100 / 100
46 ms5544 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
//#define all(x) x.begin(),x.end()
//#define rall(x) x.rbegin(),x.rend()
//#define ff first
//#define ss second
//#define pb push_back
//template<class T, class U> inline bool chmin(T& a, const U& b) { if (a > b) { a = b; return true; } return false; }
//template<class T, class U> inline bool chmax(T& a, const U& b) { if (a < b) { a = b; return true; } return false; }
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)

const int inf = 1e9, mod = 1e9 + 7;


void solve(){
	int n;
	cin >> n;
	vector<int> a{0}, pr{0};
	
	for(int i = 0; i < n; i ++ ){
		int x;
		cin >> x;
		int cnt = 1;
		for(int ms = 0; ms < 60; ms ++ ){
			if(x >> ms & 1) {
				x = x >> ms;
				break;
			}
			cnt *= 2;
		};
		a.push_back(x);
		pr.push_back(pr.back() + cnt);
		//cout << x << ' ' << cnt << '\n';
	};
	
	//for(int i : pr)cout << i << ' ';
	//cout << '\n';
	
	int q;
	cin >> q;
	while(q -- ) {
		int ps;
		cin >> ps;
		int l = 0, r = n, ans = 0;
		while(l <= r){
			int m = (l+r) >> 1;
			if(ps <= pr[m]){
				r = m - 1;
				ans = m;
			}else l = m + 1;
				
		}
		//cout << ans << ' ';
		cout << a[ans] << '\n';
	};
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    };
}














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