Submission #638758

#TimeUsernameProblemLanguageResultExecution timeMemory
638758penguin133Intercastellar (JOI22_ho_t1)C++14
100 / 100
74 ms7132 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> > 
#define fi first
#define se second
int n,k;
int A[200005], B[200005], P[200005];
void solve(){
	cin >> n;
	for(int i=1;i<=n;i++)cin >> A[i];
	for(int i=1;i<=n;i++){
		B[i] = 1;
		while(A[i]%2 == 0)A[i] /= 2, B[i]*=2;
		P[i] = P[i-1] + B[i];
	}
	int q;cin >> q;
	while(q--){
		int x;cin >> x;
		int s = 1, e = n, ans = 0;
		while(s <= e){
			int m = (s + e)/2;
			if(P[m] < x)ans = m, s = m + 1;
			else e = m - 1;
		}
		cout << A[ans+1] << '\n';
		
	}
	
}
 
main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

Compilation message (stderr)

Main.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...