#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
ll read() { // read int128
int x; cin >> x; return (ll)x;
}
long long bm(long long b, long long p) {
if(p==0) return 1 % MOD;
long long r = bm(b, p >> 1);
if(p&1) return (((r*r) % MOD) * b) % MOD;
return (r*r) % MOD;
}
long long inv(long long b) {
return bm(b, MOD-2);
}
long long f[MAXN];
long long nCr(int n, int r) {
long long ans = f[n]; ans *= inv(f[r]); ans %= MOD;
ans *= inv(f[n-r]); ans %= MOD; return ans;
}
void precomp() {
for(int i=0; i<MAXN; i++) f[i] = (i == 0 ? 1 % MOD : (f[i-1] * i) % MOD);
}
void solve(int tc) {
int n;
cin >> n;
int a[n+1];
for(int i=1; i<=n; i++)cin >> a[i];
int ps[n+1];
ps[0] = 0;
int c[n+1];
for(int i=1; i<=n; i++) {
ps[i] = ps[i-1];
int add = 0;
int b = a[i];
while(!(b & 1)) {
b >>= 1;
add++;
}
c[i] = b;
ps[i] += (1ll << add);
}
int q;
cin >> q;
while(q--) {
int x;
cin >> x;
int lb = 1, rb = n;
while(lb < rb) {
int mid = (lb + rb) >> 1;
if(ps[mid] < x) lb = mid + 1;
else rb = mid;
}
cout << c[lb] << "\n";
}
}
int32_t main(){
precomp();
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1876 KB |
Output is correct |
2 |
Correct |
4 ms |
1804 KB |
Output is correct |
3 |
Correct |
22 ms |
7212 KB |
Output is correct |
4 |
Correct |
34 ms |
4232 KB |
Output is correct |
5 |
Correct |
66 ms |
8652 KB |
Output is correct |
6 |
Correct |
35 ms |
6892 KB |
Output is correct |
7 |
Correct |
59 ms |
8644 KB |
Output is correct |
8 |
Correct |
54 ms |
8776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1876 KB |
Output is correct |
2 |
Correct |
3 ms |
1888 KB |
Output is correct |
3 |
Correct |
3 ms |
1884 KB |
Output is correct |
4 |
Correct |
4 ms |
1888 KB |
Output is correct |
5 |
Correct |
3 ms |
1876 KB |
Output is correct |
6 |
Correct |
3 ms |
2000 KB |
Output is correct |
7 |
Correct |
3 ms |
1876 KB |
Output is correct |
8 |
Correct |
3 ms |
1900 KB |
Output is correct |
9 |
Correct |
3 ms |
1892 KB |
Output is correct |
10 |
Correct |
4 ms |
1916 KB |
Output is correct |
11 |
Correct |
4 ms |
2004 KB |
Output is correct |
12 |
Correct |
3 ms |
1904 KB |
Output is correct |
13 |
Correct |
4 ms |
1876 KB |
Output is correct |
14 |
Correct |
4 ms |
1900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1876 KB |
Output is correct |
2 |
Correct |
4 ms |
1804 KB |
Output is correct |
3 |
Correct |
22 ms |
7212 KB |
Output is correct |
4 |
Correct |
34 ms |
4232 KB |
Output is correct |
5 |
Correct |
66 ms |
8652 KB |
Output is correct |
6 |
Correct |
35 ms |
6892 KB |
Output is correct |
7 |
Correct |
59 ms |
8644 KB |
Output is correct |
8 |
Correct |
54 ms |
8776 KB |
Output is correct |
9 |
Correct |
2 ms |
1876 KB |
Output is correct |
10 |
Correct |
3 ms |
1888 KB |
Output is correct |
11 |
Correct |
3 ms |
1884 KB |
Output is correct |
12 |
Correct |
4 ms |
1888 KB |
Output is correct |
13 |
Correct |
3 ms |
1876 KB |
Output is correct |
14 |
Correct |
3 ms |
2000 KB |
Output is correct |
15 |
Correct |
3 ms |
1876 KB |
Output is correct |
16 |
Correct |
3 ms |
1900 KB |
Output is correct |
17 |
Correct |
3 ms |
1892 KB |
Output is correct |
18 |
Correct |
4 ms |
1916 KB |
Output is correct |
19 |
Correct |
4 ms |
2004 KB |
Output is correct |
20 |
Correct |
3 ms |
1904 KB |
Output is correct |
21 |
Correct |
4 ms |
1876 KB |
Output is correct |
22 |
Correct |
4 ms |
1900 KB |
Output is correct |
23 |
Correct |
53 ms |
4892 KB |
Output is correct |
24 |
Correct |
67 ms |
7816 KB |
Output is correct |
25 |
Correct |
90 ms |
11896 KB |
Output is correct |
26 |
Correct |
51 ms |
8140 KB |
Output is correct |
27 |
Correct |
67 ms |
8268 KB |
Output is correct |
28 |
Correct |
94 ms |
12364 KB |
Output is correct |
29 |
Correct |
124 ms |
11824 KB |
Output is correct |
30 |
Correct |
49 ms |
5460 KB |
Output is correct |
31 |
Correct |
121 ms |
12232 KB |
Output is correct |