求调,出现了re
查看原帖
求调,出现了re
1229738
CyansQwQ楼主2024/7/14 16:25

感觉我的思路比较简单,但是有re的点,蒟蒻求助大佬帮帮忙。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e8+10;
ll res[N];
void solve()
{
	ll n;
	cin>>n;
	vector<ll>a;
	for(ll i=1,j=1;i<=n;i++,j++)
	{
		ll num,s=1;cin>>num;
		if(num%2==0)
		{
			while(num%2==0)s*=2,num/=2;
			j+=s-1;
		}
		res[j]=num;
		a.push_back(j);
	}
	
	ll q;cin>>q;
	while(q--)
	{
		ll x;cin>>x;
		ll l=-1,r=a.size();
		while(l+1<r)
		{
			ll mid=l+r>>1;
			if(x<=a[mid])r=mid;
			else l=mid;
		}
		cout<<res[a[r]]<<endl;
	}
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	solve();return 0;
}
2024/7/14 16:25
加载中...