QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#1056#671403#21686. 【NOIP Round #2】恰钱Happy_mouseqiuzijin2026Failed.2024-10-24 12:21:272024-10-24 12:21:28

详细

Extra Test:

Accepted
time: 25ms
memory: 10860kb

input:

1
2 2

output:

2

result:

ok Accepted!

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671403#21686. 【NOIP Round #2】恰钱qiuzijin2026100 ✓63ms12384kbC++14912b2024-10-24 12:15:062024-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;
}