UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214958#3855. 好数lqw0281ms1344kbC++1.2kb2024-11-24 12:56:432024-11-24 13:16:27

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, mid;
        while(1){
            mid = (ll + rr) / 2;
            if(a[mid] < l) ll = mid+1;
            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
Wrong Answer

Test #1:

score: 30
Accepted
time: 0ms
memory: 1340kb

input:

1
999995700 1000000000

output:

-1

result:

ok Accepted! >_<


Test #2:

score: -30
Wrong Answer
time: 145ms
memory: 1344kb

input:

100000
7857167 7862247
8344618 8348655
8382478 8388566
8315927 8321011
8246290 8250342
8382480 83885...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
8370176
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1...

result:

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


Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 136ms
memory: 1344kb

input:

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

output:

-1
7332864
8250368
8124416
8378368
8348672
8321024
4192256
8250368
8311808
8348672
6280192
4178432
7...

result:

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


Subtask #3:

score: 0
Skipped