QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1057#671384#21686. 【NOIP Round #2】恰钱hemuzhoud909RCAFailed.2024-10-24 15:12:342024-10-24 15:12:35

Details

Extra Test:

Accepted
time: 58ms
memory: 12868kb

input:

1
1 1000000000

output:

2

result:

ok Accepted!

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671384#21686. 【NOIP Round #2】恰钱d909RCA100 ✓171ms14804kbC++14679b2024-10-24 12:10:202024-10-24 12:10:21

answer

#include <bits/stdc++.h>
using namespace std; 
#define int long long
int T,n,a[100000009];
queue<pair<int,int> > q;
map<int,bool> v;
signed main()
{
//	freopen("qiaqia.in","r",stdin);
//	freopen("qiaqia.out","w",stdout);
	q.push({2,1});
	while(!q.empty())
	{
		pair<int,int> x=q.front();
		q.pop();
		if(x.first>1e9) continue ;
		a[++a[0]]=x.first;
		for(int i=x.second+1;i<=30;i++)
		{
			q.push({(x.first+(int)pow(2,i))<<1,i+1}); 
		}
	}
	sort(a+1,a+a[0]+1);
//	cout<<a[0]<<'\n';
	cin>>T;
	while(T--)
	{
		int l,r;
		cin>>l>>r;
		int x=lower_bound(a+1,a+a[0]+1,l)-a;
		if(r>=a[x]&&a[x]) cout<<a[x]<<'\n';
		else cout<<-1<<'\n';
	}
	return 0;
}