#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 4e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], cnt[mxN], pre[mxN];
int Odd(int x){
while (x%2 == 0) x /= 2;
return x;
}
int BS(ll i){
int l = 0, r = n-1, ans = -1;
while (l <= r){
int k = (l + r + 1)>>1;
if (pre[k] < i){
ans = k;
l = k + 1;
}
else r = k - 1;
}
return a[ans+1];
}
void Solve(){
cin >> n;
for (int i = 0; i < n; i++){
cin >> a[i];
int x = Odd(a[i]);
cnt[i] = a[i]/x;
a[i] = x;
pre[i] = (i ? pre[i-1] : 0) + cnt[i];
}
cin >> m;
while (m--){
rl(i);
cout << BS(i) << en;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
cout << setprecision(12) << fixed;
cerr << setprecision(12) << fixed;
cerr << "Started!" << endl;
int t = 1;
//cin >> t;
while (t--)
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
19 ms |
4920 KB |
Output is correct |
4 |
Correct |
29 ms |
1756 KB |
Output is correct |
5 |
Correct |
48 ms |
5812 KB |
Output is correct |
6 |
Correct |
28 ms |
5360 KB |
Output is correct |
7 |
Correct |
51 ms |
7156 KB |
Output is correct |
8 |
Correct |
49 ms |
7244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
19 ms |
4920 KB |
Output is correct |
4 |
Correct |
29 ms |
1756 KB |
Output is correct |
5 |
Correct |
48 ms |
5812 KB |
Output is correct |
6 |
Correct |
28 ms |
5360 KB |
Output is correct |
7 |
Correct |
51 ms |
7156 KB |
Output is correct |
8 |
Correct |
49 ms |
7244 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
38 ms |
3272 KB |
Output is correct |
24 |
Correct |
38 ms |
6324 KB |
Output is correct |
25 |
Correct |
68 ms |
10368 KB |
Output is correct |
26 |
Correct |
45 ms |
6528 KB |
Output is correct |
27 |
Correct |
40 ms |
6636 KB |
Output is correct |
28 |
Correct |
86 ms |
10912 KB |
Output is correct |
29 |
Correct |
76 ms |
10332 KB |
Output is correct |
30 |
Correct |
38 ms |
3916 KB |
Output is correct |
31 |
Correct |
76 ms |
10680 KB |
Output is correct |