#include<bits/stdc++.h>
using namespace std;
#define int long long
bool debug = false;
int mod = 1e9+7;
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, q, temp; cin >> n;
vector<pair<int, int>> v(n);
for (int i =0 ;i < n; ++i){
cin >> v[i].first;
}
for (int i = n-1; i >= 0; --i){
if(v[i].first%2 == 0){
temp = (v[i].first&(-v[i].first+1));
v[i].second = temp;
v[i].first = v[i].first/temp;
temp = v[i].first;
v[i].first = v[i].second;
v[i].second = temp;
}
else{
v[i].second = v[i].first;
v[i].first = 1;
}
}
int sum = 0;
vector<int> in(n);
for (int i = 0; i < n; ++i){
sum += v[i].first;
in[i] = sum;
}
if(debug){
for (int i = 0;i < n; ++i){
cout << in[i] << ' ';
}
}
cin >> q;
for (int i = 0; i < q;++i){
cin >> temp;
cout << v[lower_bound(in.begin(), in.end(), temp)-in.begin()].second << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
20 ms |
5460 KB |
Output is correct |
4 |
Correct |
30 ms |
2744 KB |
Output is correct |
5 |
Correct |
51 ms |
7100 KB |
Output is correct |
6 |
Correct |
28 ms |
5396 KB |
Output is correct |
7 |
Correct |
50 ms |
7148 KB |
Output is correct |
8 |
Correct |
49 ms |
7188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 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 |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
20 ms |
5460 KB |
Output is correct |
4 |
Correct |
30 ms |
2744 KB |
Output is correct |
5 |
Correct |
51 ms |
7100 KB |
Output is correct |
6 |
Correct |
28 ms |
5396 KB |
Output is correct |
7 |
Correct |
50 ms |
7148 KB |
Output is correct |
8 |
Correct |
49 ms |
7188 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 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 |
332 KB |
Output is correct |
23 |
Correct |
27 ms |
3276 KB |
Output is correct |
24 |
Correct |
33 ms |
6360 KB |
Output is correct |
25 |
Correct |
66 ms |
10356 KB |
Output is correct |
26 |
Correct |
43 ms |
6516 KB |
Output is correct |
27 |
Correct |
38 ms |
6652 KB |
Output is correct |
28 |
Correct |
76 ms |
10736 KB |
Output is correct |
29 |
Correct |
71 ms |
10180 KB |
Output is correct |
30 |
Correct |
40 ms |
3900 KB |
Output is correct |
31 |
Correct |
76 ms |
10704 KB |
Output is correct |