#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define s second
#define f first
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
#define pii pair <int,int>
#define int ll
using namespace std;
const int N = 2e5 + 5;
int a[N],pr[N];
pii v[N];
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>> n;
for (int i = 1; i <= n; i++)
cin>>a[i];
int id = 0;
for (int i= 1; i <= n; i++){
if (a[i] & 1) {
v[i] = {1,a[i]};
continue;
}
int x = 2;
for (int j = 1; j <= 50; j++){
if ((a[i] % (1LL<<j)) == 0){
x = (1LL<<j);
}else{
break;
}
}
v[i] = {x,a[i]/x};
}
for (int i = 1; i <= n; i++){
pr[i] = pr[i - 1] + v[i].f;
}
int Q;
cin>>Q;
while (Q--){
int x;
cin>>x;
int l = 1,r = n,res;
while (l <= r){
int mid = (l + r)/2;
if (pr[mid] >= x){
r = mid - 1;
res = mid;
}else{
l = mid + 1;
}
}
cout<<v[res].s<<endl;
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:26:6: warning: unused variable 'id' [-Wunused-variable]
26 | int id = 0;
| ^~
Main.cpp:4:11: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
4 | #define s second
| ^~~~~~
Main.cpp:56:19: note: 'res' was declared here
56 | int l = 1,r = n,res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
52 ms |
6996 KB |
Output is correct |
4 |
Correct |
164 ms |
3036 KB |
Output is correct |
5 |
Correct |
230 ms |
8632 KB |
Output is correct |
6 |
Correct |
114 ms |
6604 KB |
Output is correct |
7 |
Correct |
230 ms |
8676 KB |
Output is correct |
8 |
Correct |
228 ms |
8676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 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 |
2 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
52 ms |
6996 KB |
Output is correct |
4 |
Correct |
164 ms |
3036 KB |
Output is correct |
5 |
Correct |
230 ms |
8632 KB |
Output is correct |
6 |
Correct |
114 ms |
6604 KB |
Output is correct |
7 |
Correct |
230 ms |
8676 KB |
Output is correct |
8 |
Correct |
228 ms |
8676 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
332 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 |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
148 ms |
3532 KB |
Output is correct |
24 |
Correct |
109 ms |
7368 KB |
Output is correct |
25 |
Correct |
241 ms |
11916 KB |
Output is correct |
26 |
Correct |
145 ms |
7508 KB |
Output is correct |
27 |
Correct |
133 ms |
7732 KB |
Output is correct |
28 |
Correct |
264 ms |
12292 KB |
Output is correct |
29 |
Correct |
298 ms |
11728 KB |
Output is correct |
30 |
Correct |
176 ms |
4060 KB |
Output is correct |
31 |
Correct |
275 ms |
12168 KB |
Output is correct |