Submission #815905

#TimeUsernameProblemLanguageResultExecution timeMemory
815905vjudge1Intercastellar (JOI22_ho_t1)C++17
100 / 100
283 ms10852 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

void open(){
	if(fopen("input.inp", "r")){
		freopen("input.inp", "r", stdin);
		//freopen("output.out", "w", stdout);
	}
}

const int maxn = 2e5 + 5;

int n;
int A[maxn];
int q;
int lowest[maxn];
int depth[maxn];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	open();

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> A[i];
		int temp = A[i];
		int cnt = 0;
		while(temp % 2 == 0){
			temp /= 2;
			cnt++;
		}

		lowest[i] = temp;
		depth[i] = (1LL << cnt);
	}

	int cur_pos = 0;
	int prefix = 0;
	
	cin >> q;
	while(q--){
		int x;
		cin >> x;
		while(cur_pos < n && prefix < x){
			prefix += depth[++cur_pos];
		}

		cout << lowest[cur_pos] << endl;
	}

	return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void open()':
Main.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...