#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define db double
#define int long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;
const int Max = 1e6 + 7, Inf = 1e9 + 7;
void print(bool x) { cout << (x ? "Yes" : "No") << endl; }
void solve()
{
int n; cin >> n;
vector <pair<int, int>> p(n + 1, {0, 1});
for(int i = 0; i < n; i++)
{
cin >> p[i].fs;
while(p[i].fs % 2 == 0)
{
p[i].fs /= 2;
p[i].sd *= 2;
}
}
p[n].sd = long(1e15);
for(int i = 1; i <= n; i++)
p[i].sd += p[i - 1].sd;
int q; cin >> q;
while(q--)
{
int x; cin >> x;
int a = -1, b = n;
while(abs(a - b) != 1)
{
int c = (a + b) / 2;
if(p[c].sd >= x)
b = c;
else
a = c;
}
cout << p[b].fs << endl;
}
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int Q = 1; //cin >> Q;
while(Q--)
{
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
18 ms |
4140 KB |
Output is correct |
4 |
Correct |
31 ms |
2452 KB |
Output is correct |
5 |
Correct |
52 ms |
5628 KB |
Output is correct |
6 |
Correct |
29 ms |
4184 KB |
Output is correct |
7 |
Correct |
51 ms |
5696 KB |
Output is correct |
8 |
Correct |
58 ms |
5716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
18 ms |
4140 KB |
Output is correct |
4 |
Correct |
31 ms |
2452 KB |
Output is correct |
5 |
Correct |
52 ms |
5628 KB |
Output is correct |
6 |
Correct |
29 ms |
4184 KB |
Output is correct |
7 |
Correct |
51 ms |
5696 KB |
Output is correct |
8 |
Correct |
58 ms |
5716 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
28 ms |
3164 KB |
Output is correct |
24 |
Correct |
31 ms |
5304 KB |
Output is correct |
25 |
Correct |
64 ms |
8788 KB |
Output is correct |
26 |
Correct |
41 ms |
5716 KB |
Output is correct |
27 |
Correct |
37 ms |
5712 KB |
Output is correct |
28 |
Correct |
80 ms |
9300 KB |
Output is correct |
29 |
Correct |
72 ms |
8860 KB |
Output is correct |
30 |
Correct |
39 ms |
3664 KB |
Output is correct |
31 |
Correct |
72 ms |
9080 KB |
Output is correct |