# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
938604 | vjudge1 | Intercastellar (JOI22_ho_t1) | C++17 | 48 ms | 3156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
vector<int> sums(n);
for (int i = 0; i < n; i++)
{
int temp = v[i];
int cnt = 0;
while (temp%2==0)
{
temp/=2;
cnt++;
}
sums[i] = cnt;
}
vector<int> pref_sum(n,0);
pref_sum[0] = (1<<sums[0]);
for (int i = 1; i < n; i++)
pref_sum[i] = pref_sum[i-1]+(1<<sums[i]);
int q;
cin >> q;
while(q--)
{
int x;
cin >> x;
int l = 0, r = n-1;
while (r-l>1)
{
int mid = l+r>>1;
if (pref_sum[mid] <= x)
l = mid;
else
r = mid;
}
if (pref_sum[l] >= x)
cout << v[l]/(1<<(sums[l])) << '\n';
else
cout << v[r]/(1<<(sums[r])) << '\n';
}
return 0;
}
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... |