QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1060 | #671384 | #21686. 【NOIP Round #2】恰钱 | hemuzhou | d909RCA | Failed. | 2024-10-24 15:14:02 | 2024-10-24 15:14:02 |
Details
Extra Test:
Accepted
time: 55ms
memory: 13992kb
input:
1 1 1000000000
output:
2
result:
ok Accepted!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671384 | #21686. 【NOIP Round #2】恰钱 | d909RCA | 100 ✓ | 171ms | 14804kb | C++14 | 679b | 2024-10-24 12:10:20 | 2024-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;
}