# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1168832 | CrabCNH | Intercastellar (JOI22_ho_t1) | C++20 | 46 ms | 5448 KiB |
#include <bits/stdc++.h>
#define task "BriantheCrab"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
using namespace std;
template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}
const int maxN = 2e5 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;
int a[maxN], d[maxN];
void solve () {
int n;
cin >> n;
for (int i = 1; i <= n; i ++) {
int x;
cin >> x;
d[i] = d[i - 1];
int cur = 0;
while (x % 2 == 0) {
x /= 2;
cur++;
}
d[i] += (1 << cur);
a[i] = x;
}
// for (int i = 1; i <= n; i ++) {
// cout << d[i] << ' ';
// }
//cout << '\n';
int q;
cin >> q;
while (q --) {
int x;
cin >> x;
int l = 1, r = n, pos = -1;
while (true) {
if (l > r) {
break;
}
int mid = (l + r) >> 1;
//cout << l << ' ' << r << ' ' << mid << ' ' << d[mid] << '\n';
if (d[mid] >= x) {
pos = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
//cout << pos << ' ';
cout << a[pos] << '\n';
}
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
solve ();
}
return 0;
}
// thfdgb
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |