Submission #1359262

#TimeUsernameProblemLanguageResultExecution timeMemory
1359262NAMINIntercastellar (JOI22_ho_t1)C++20
100 / 100
41 ms6868 KiB
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;

void solve(){
	int N;
	cin >> N;
	vector<ll> a(N);
	for(int i=0;i<N;i++)
		cin >> a[i];

	vector<ll> taille(N,1);
	for(int i=0;i<N;i++){
		while((taille[i]&a[i])==0){
			taille[i]*=2;
		}
	}
	
	vector<ll> pref(N+1,0);
	for(int i=1;i<=N;i++){
		pref[i]=pref[i-1]+taille[i-1];
	}
	
	int Q;
	cin >> Q;
	while(Q--){
		ll idxpart;
		cin >> idxpart;
		ll res = 1;
		int lo=1,hi=N;
		while(lo<=hi){
			int mid = lo+(hi-lo)/2;
			if(pref[mid]>=idxpart){
				res=a[mid-1]/taille[mid-1];
				hi=mid-1;
			}
			else
				lo=mid+1;
		}
		cout << res << endl;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...