Submission #995219

#TimeUsernameProblemLanguageResultExecution timeMemory
995219mnieplowiczIntercastellar (JOI22_ho_t1)C++14
100 / 100
64 ms7640 KiB
#include <bits/stdc++.h>
using namespace std;

long long tab[200005];
long long dwa[40];

void D(){
	dwa[0] = 1;
	for(int i = 1; i <= 31; i++) dwa[i] = dwa[i-1]*2;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	D();
	
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> tab[i];
	int q;
	cin >> q;
	long long l = 0;
	int ind = 0;
	while(q--){
		long long x;
		long long occ, val;
		cin >> x;
		if(x <= l){
			cout << val <<'\n';
			continue;
		}
		//cerr << ind << " " << tab[ind] << " " << l << " " << x<< ":"<<'\n';
		while(l < x){
			//cerr << occ << " " << val << " " << l << '\n';
			occ = 1, val = tab[ind];
			for(int i = 30; i >= 0; i--){
				if(val % dwa[i] == 0){
					//cerr << i << '\n';
					occ *= dwa[i];
					val /= dwa[i];
				}
			}
			ind++;
			l += occ;
		}
		cout << val << '\n';
	}
			
		
	
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...