#include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<pair<ll,ll>> vec;
for(int i = 0;i<N;++i){
ll x; cin >> x;
ll cur = 1;
while(x % cur == 0){
cur *= 2;
}
cur /= 2; x /= cur;
vec.push_back({cur,x});
}
int Q; cin >> Q;
vector<pair<ll,int>> queries; //value, index
for(int i = 0;i<Q;++i){
ll x; cin >> x;
queries.push_back({x,i});
}
sort(queries.begin(),queries.end());
vector<int> ans(Q,0);
int j = 0; ll cnt = 0ll;
for(int i = 0;i<Q;++i){
while(j < N && cnt+vec[j].f < queries[i].f){
cnt += vec[j].f;
++j;
}
ans[queries[i].s] = vec[j].s;
}
for(int i = 0;i<Q;++i){
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
5796 KB |
Output is correct |
4 |
Correct |
19 ms |
6996 KB |
Output is correct |
5 |
Correct |
31 ms |
13700 KB |
Output is correct |
6 |
Correct |
25 ms |
8396 KB |
Output is correct |
7 |
Correct |
30 ms |
11472 KB |
Output is correct |
8 |
Correct |
35 ms |
11468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
604 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 |
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 |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
14 ms |
5796 KB |
Output is correct |
4 |
Correct |
19 ms |
6996 KB |
Output is correct |
5 |
Correct |
31 ms |
13700 KB |
Output is correct |
6 |
Correct |
25 ms |
8396 KB |
Output is correct |
7 |
Correct |
30 ms |
11472 KB |
Output is correct |
8 |
Correct |
35 ms |
11468 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 |
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 |
604 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
17 ms |
5464 KB |
Output is correct |
24 |
Correct |
21 ms |
10188 KB |
Output is correct |
25 |
Correct |
40 ms |
13768 KB |
Output is correct |
26 |
Correct |
28 ms |
7768 KB |
Output is correct |
27 |
Correct |
33 ms |
10344 KB |
Output is correct |
28 |
Correct |
53 ms |
14528 KB |
Output is correct |
29 |
Correct |
50 ms |
14272 KB |
Output is correct |
30 |
Correct |
25 ms |
9048 KB |
Output is correct |
31 |
Correct |
49 ms |
14284 KB |
Output is correct |