//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = int64_t;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define dbg(x) cerr << #x << ": " << x << '\n';
int32_t main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cout.tie(nullptr); cerr.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vector<pair<ll, ll>> data;
data.push_back({0, 0});
for (ll i = 0; i < n; i++) {
ll p = a[i];
while (!(p & 1)) {
p >>= 1;
}
data.push_back({data.back().first + a[i] / p, p});
}
ll q;
cin >> q;
while (q--) {
ll x;
cin >> x;
ll lb = 0, rb = data.size() - 1, ans = 0;
while (lb <= rb) {
int mb = lb + rb >> 1;
if (data[mb].first >= x) {
ans = mb;
rb = mb - 1;
} else {
lb = mb + 1;
}
}
cout << data[ans].second << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:38:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | int mb = lb + rb >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
22 ms |
7708 KB |
Output is correct |
4 |
Correct |
22 ms |
3028 KB |
Output is correct |
5 |
Correct |
38 ms |
7888 KB |
Output is correct |
6 |
Correct |
22 ms |
6636 KB |
Output is correct |
7 |
Correct |
37 ms |
8416 KB |
Output is correct |
8 |
Correct |
38 ms |
8832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
0 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 |
0 ms |
528 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
22 ms |
7708 KB |
Output is correct |
4 |
Correct |
22 ms |
3028 KB |
Output is correct |
5 |
Correct |
38 ms |
7888 KB |
Output is correct |
6 |
Correct |
22 ms |
6636 KB |
Output is correct |
7 |
Correct |
37 ms |
8416 KB |
Output is correct |
8 |
Correct |
38 ms |
8832 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
0 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 |
0 ms |
528 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
22 ms |
3520 KB |
Output is correct |
24 |
Correct |
25 ms |
7380 KB |
Output is correct |
25 |
Correct |
58 ms |
10436 KB |
Output is correct |
26 |
Correct |
42 ms |
6856 KB |
Output is correct |
27 |
Correct |
29 ms |
7636 KB |
Output is correct |
28 |
Correct |
57 ms |
10848 KB |
Output is correct |
29 |
Correct |
50 ms |
11384 KB |
Output is correct |
30 |
Correct |
27 ms |
4188 KB |
Output is correct |
31 |
Correct |
59 ms |
11212 KB |
Output is correct |