#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
constexpr int INF = (int)2e9;
constexpr int N = (int)4e5 + 111;
constexpr int md = (int)1e9+7;
constexpr int mdPower = (int)1e9+7 - 1;
constexpr double eps = 1e-7;
typedef __int128 _uint;
typedef long long ll;
mt19937_64 rnd(time(nullptr));
void add(int& a,int b){
a += b; if(a >= md) a -= md;
}
void sub(int& a,int b){
a -= b; while(a < 0) a += md;
}
void add(__int128& a,int b){
a += b;
}
void sub(__int128& a,int b){
a -= b;
}
int bpow(int a,int b){
if(b == 0)
return 1;
if(b % 2 == 0){
int t = bpow(a,b>>1);
return 1ll*t*t%md;
}
return 1ll * a*bpow(a,b-1) % md;
}
int inv(int a){
return bpow(a,md-2);
}
//int fac[N],invfac[N];
//
//void init(){
// fac[0] = 1;
// for(int i = 1; i < N; i++){
// fac[i] = (fac[i-1] * i) % md;
// }
// invfac[N-1] = inv(fac[N-1]);
// for(int i = N-2; i >= 0; i--){
// invfac[i] = (invfac[i+1] * (i+1))%md;
// }
// return;
//}
//
//int C(int n,int k){
// if(k > n)
// return 0;
// return fac[n] * invfac[k] % md * invfac[n-k] % md;
//}
//
//int A(int n,int k){
// if(k > n)
// return 0;
// return fac[n] * invfac[n-k] % md;
//
void solve(){
int n;
cin >> n;
int a[n],cnt[n];
for(int i = 0; i < n; i++){
cin >> a[i];
cnt[i] = 1;
while(a[i] % 2 == 0){
a[i] /= 2;
cnt[i] *= 2;
}
}
int q;
cin >> q;
int ans[q];
vector<pair<int,int>> v;
for(int i = 0; i < q; i++){
int x;
cin >> x;
v.pb(mp(x,i));
}
sort(v.begin(),v.end());
int p = 0;
int sum = 0;
for(auto&[x,id] : v){
while(sum + cnt[p] < x){
sum += cnt[p];
p++;
}
ans[id] = a[p];
}
for(int i = 0; i < q; i++){
cout << ans[i] << "\n";
}
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int tests = 1;
// cin >> tests;
for(int test = 1; test <= tests; test++){
// cerr << "test = " << test << "\n";
solve();
}
return 0;
}
/**
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
24 ms |
5320 KB |
Output is correct |
4 |
Correct |
30 ms |
7488 KB |
Output is correct |
5 |
Correct |
46 ms |
10580 KB |
Output is correct |
6 |
Correct |
32 ms |
6752 KB |
Output is correct |
7 |
Correct |
59 ms |
10692 KB |
Output is correct |
8 |
Correct |
52 ms |
10688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
332 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
24 ms |
5320 KB |
Output is correct |
4 |
Correct |
30 ms |
7488 KB |
Output is correct |
5 |
Correct |
46 ms |
10580 KB |
Output is correct |
6 |
Correct |
32 ms |
6752 KB |
Output is correct |
7 |
Correct |
59 ms |
10692 KB |
Output is correct |
8 |
Correct |
52 ms |
10688 KB |
Output is correct |
9 |
Correct |
0 ms |
324 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 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 |
26 ms |
5916 KB |
Output is correct |
24 |
Correct |
31 ms |
7244 KB |
Output is correct |
25 |
Correct |
61 ms |
13644 KB |
Output is correct |
26 |
Correct |
40 ms |
8160 KB |
Output is correct |
27 |
Correct |
39 ms |
7828 KB |
Output is correct |
28 |
Correct |
74 ms |
13944 KB |
Output is correct |
29 |
Correct |
72 ms |
13496 KB |
Output is correct |
30 |
Correct |
38 ms |
8312 KB |
Output is correct |
31 |
Correct |
72 ms |
13956 KB |
Output is correct |