UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214956#3855. 好数lqw0178ms1340kbC++1.2kb2024-11-24 12:52:452024-11-24 13:16:18

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#define int long long
const int N = 1e9+10;
const int NN = 2e4+10;
using namespace std;
int qmi(int a, int k)
{
    int res = 1;
    while (k)
    {
        if (k & 1) res = res * a;
        a = a * a;
        k >>= 1;
    }
    return res;
}
int a[NN],cnt,la;
int get_1(int n){
    int re = 0;
    while (n){
        if (n % 2 == 1){
            re ++;
        }
        n /= 2;
    }
    return re;
}
void init()
{
    int j = -1;
    while (la <= N){
        j += 2;
        a[cnt++] = j << get_1(j);
        la = a[cnt-1];
    }
    sort(a,a + cnt);
}
signed main(){
    init();
    //cout << NN << ' ' << cnt << '\n';
    //for (int i = 0; i < cnt; i ++ )cout << a[i] << " ";
    int q;
    cin >> q;
    while (q -- ){
        int l,r;
        cin >> l >> r;
        int ll = 0, rr = cnt-1, mid;
        while(1){
            mid = (ll + rr) / 2;
            if(a[mid] < l) ll = mid;
            if(a[mid] > r) rr = mid;
            if(a[mid] >= l && a[mid] <= r) break;
            if(a[mid-1] <= l && a[mid] >= r) break;
        }
        if(a[mid] > r )cout << -1 <<'\n';
        else cout << a[mid] << '\n';
    }
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

1
999995700 1000000000

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 178ms
memory: 1340kb

input:

100000
8382464 8388612
7332864 7337984
8250368 8255488
8119296 8124416
8373248 8378368
8348672 83537...

output:

8382464
7337984
8255488
8119296
8373248
8353792
8315904
4187136
8246272
8315904
8344576
6284288
4174...

result:

wrong answer There is a valid number but you did not find it.


Subtask #3:

score: 0
Skipped