#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937_64 mt(418);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#else
freopen("input.txt", "r", stdin);
#endif
// srand(time(0));
init();
cout << fixed << setprecision(20);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
void solve() {
int n;
cin >> n;
vector<ll> a(n), b(n, 1), pref(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
while (~a[i] & 1) {
b[i] <<= 1;
a[i] >>= 1;
}
}
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i] + b[i];
}
int q;
cin >> q;
while (q--) {
ll x;
cin >> x;
int l = -1, r = n + 1;
while (r - l > 1) {
int m = (r + l) / 2;
if (pref[m] >= x) {
r = m;
} else {
l = m;
}
}
cout << a[l] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
17 ms |
4996 KB |
Output is correct |
4 |
Correct |
30 ms |
1680 KB |
Output is correct |
5 |
Correct |
61 ms |
5456 KB |
Output is correct |
6 |
Correct |
28 ms |
4444 KB |
Output is correct |
7 |
Correct |
49 ms |
5460 KB |
Output is correct |
8 |
Correct |
48 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
17 ms |
4996 KB |
Output is correct |
4 |
Correct |
30 ms |
1680 KB |
Output is correct |
5 |
Correct |
61 ms |
5456 KB |
Output is correct |
6 |
Correct |
28 ms |
4444 KB |
Output is correct |
7 |
Correct |
49 ms |
5460 KB |
Output is correct |
8 |
Correct |
48 ms |
5376 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
29 ms |
3292 KB |
Output is correct |
24 |
Correct |
39 ms |
6468 KB |
Output is correct |
25 |
Correct |
63 ms |
10384 KB |
Output is correct |
26 |
Correct |
39 ms |
6740 KB |
Output is correct |
27 |
Correct |
38 ms |
6736 KB |
Output is correct |
28 |
Correct |
70 ms |
10836 KB |
Output is correct |
29 |
Correct |
66 ms |
10240 KB |
Output is correct |
30 |
Correct |
48 ms |
3924 KB |
Output is correct |
31 |
Correct |
71 ms |
10724 KB |
Output is correct |