QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1062#671384#21686. 【NOIP Round #2】恰钱hemuzhoud909RCAFailed.2024-10-24 15:16:572024-10-24 15:16:57

详细

Extra Test:

Accepted
time: 111ms
memory: 13792kb

input:

100000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 10000...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok Accepted!

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#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;
}