QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1055 | #671403 | #21686. 【NOIP Round #2】恰钱 | Happy_mouse | qiuzijin2026 | Failed. | 2024-10-24 12:20:59 | 2024-10-24 12:21:00 |
Details
Extra Test:
Accepted
time: 29ms
memory: 12152kb
input:
1 2 2
output:
2
result:
ok Accepted!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#671403 | #21686. 【NOIP Round #2】恰钱 | qiuzijin2026 | 100 ✓ | 63ms | 12384kb | C++14 | 912b | 2024-10-24 12:15:06 | 2024-10-24 12:15:07 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll god_n[6000006];
int nl;
void dfs(int w,int yis,int wy,ll now){
if(yis>w) return;
if(w==0){
now=now<<1ll|1;
now<<=wy;
god_n[++nl]=now;
return;
}
dfs(w-1,yis,wy,now<<1);
if(yis) dfs(w-1,yis-1,wy,now<<1|1);
}
int main(){
// freopen("qiaqia.in","r",stdin);
// freopen("qiaqia.out","w",stdout);
for(int i=1;i<=31;i++){
dfs(31-i-1,i-1,i,0);
}
sort(god_n+1,god_n+nl+1);
int q;
scanf("%d",&q);
while(q--){
int ql,qr;
scanf("%d%d",&ql,&qr);
int l=1,r=nl,mid;
while(l<r){
mid=(l+r)>>1;
if(god_n[mid]<ql) l=mid+1;
else r=mid;
}
if(god_n[l]>=ql && god_n[l]<=qr) printf("%lld\n",god_n[l]);
else printf("-1\n");
}
return 0;
}