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;
#define int long long
int n,a[200005],v[200005],sp[200005];
int nr_pieces(int x)
{
if (x % 2 == 1)
return 1;
return 2 * nr_pieces(x / 2);
}
int kth(int x,int k)
{
if (x % 2 == 1)
return x;
if (k <= nr_pieces(x / 2))
return kth(x / 2,k);
else
return kth(x / 2,k - nr_pieces(x / 2));
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
v[i] = nr_pieces(a[i]);
for (int i = 1; i <= n; i++)
sp[i] = v[i] + sp[i - 1];
int q;
cin >> q;
for (int i = 1; i <= q; i++)
{
int x;
cin >> x;
int st = 0,pas = 1 << 17;
while (pas != 0)
{
if (st + pas <= n and sp[st + pas] < x)
st += pas;
pas /= 2;
}
cout << kth(a[st + 1],x - sp[st]) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |