#include <bits/stdc++.h>
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define yon(x)(x)?cout<<"YES\n":cout<<"NO\n";
#define ll int64_t
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,x) for(int i=0;i<x;i++)
#define per(i,x) for(int i=x;i>=0;i--)
using namespace std;
const ll inf =1e18+1;
const int mod=1e9+7;
ll power(ll x,ll y);
void setIO(string s);
struct segtree{
struct id{
ll a,b;
};
vector<ll>tree;
ll sz=1;
ll mrg(ll x,ll y)
{
return x+y;
}
void init(ll n)
{
sz=1;
while(sz<n)sz*=2;
tree.assign(2*sz,0);
}
void up(ll x, ll lx, ll rx,ll i, ll v)
{
if(rx-lx==1)
{
tree[x]=v;
return;
}
ll mid=(lx+rx)>>1;
if(i<mid)
{
up(2*x+1,lx,mid,i,v);
}
else{
up(2*x+2,mid,rx,i,v);
}
tree[x]=mrg(tree[2*x+1],tree[2*x+2]);
}
void up(ll i,ll v)
{
up(0,0,sz,i,v);
}
ll query(ll x,ll lx,ll rx,ll k)
{
if(rx-lx==1)
{
return lx;
}
ll mid=(lx+rx)>>1;
if(tree[2*x+1]>=k+1)
{
return query(2*x+1,lx,mid,k);
}
else{
return query(2*x+2,mid,rx,abs( tree[2*x+1]-k ) );
}
}
ll query(ll k)
{
return query(0,0,sz,k);
}
ll get(ll x,ll lx,ll rx,ll i)
{
if(rx-lx==1)
{
return tree[x];
}
ll mid=(lx+rx)>>1;
if(i<mid)
{
return get(2*x+1,lx,mid,i);
}
else{
return get(2*x+2,mid,rx,i);
}
}
ll get(ll i)
{
return get(0,0,sz,i);
}
};
void solve()
{
ll n;
cin>>n;
vector<ll>a(n);
for(int i=0;i<n;i++)
{
cin>>a[i];
}
vector<ll>b;
for(int i=0;i<n;i++)
{
ll cnt=0;
while(a[i]%2==0)
{
cnt++;
a[i]/=2;
}
for(int j=0;j<power(2,cnt);j++)
{
b.pb(a[i]);
}
}
ll q;
cin>>q;
while(q--)
{
ll c;
cin>>c;
c--;
cout<<b[c]<<endl;
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t=1;
// cin>>t;
while(t--)
{
solve();
cout<<'\n';
}
}
//********************************************************************
void setIO(string s)
{
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
inline ll power(ll x,ll y)
{
if(y==0)
{
return 1;
}
ll temp=power(x,y/2);
if(y%2==0)
{
return temp*temp;
}
else
{
return x*temp *temp;
}
}
Compilation message
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:150:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
150 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:151:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
151 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
57 ms |
6676 KB |
Output is correct |
4 |
Correct |
179 ms |
3020 KB |
Output is correct |
5 |
Correct |
249 ms |
8144 KB |
Output is correct |
6 |
Correct |
155 ms |
10448 KB |
Output is correct |
7 |
Correct |
251 ms |
10948 KB |
Output is correct |
8 |
Correct |
256 ms |
19144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Runtime error |
600 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
57 ms |
6676 KB |
Output is correct |
4 |
Correct |
179 ms |
3020 KB |
Output is correct |
5 |
Correct |
249 ms |
8144 KB |
Output is correct |
6 |
Correct |
155 ms |
10448 KB |
Output is correct |
7 |
Correct |
251 ms |
10948 KB |
Output is correct |
8 |
Correct |
256 ms |
19144 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Runtime error |
600 ms |
524288 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |