UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214951#3855. 好数lqw00ms1340kbC++998b2024-11-24 12:31:522024-11-24 13:15:59

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;
int 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];
    }
}
signed main(){
    init();
    //cout << NN << ' ' << cnt << '\n';
    sort(a,a + cnt);
    //for (int i = 0; i < cnt; i ++ )cout << a[i] << " ";
    int q;
    cin >> q;
    while (q -- ){
        int l,r,i=0;
        cin >> l >> r;
        while(a[i] < l )i++;
        if(a[i] > r )cout << -1 <<'\n';
        else cout << a[i] << '\n';
    }
}

详细

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

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

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

input:

1
999995700 1000000000

output:

-1

result:

ok Accepted! >_<


Test #2:

score: -30
Time Limit Exceeded

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:


Subtask #2:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

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

output:

8382464
7332864
8250368
8119296
8373248
8348672
8315904
4187136
8246272
8311808
8344576
6280192
4174...

result:


Subtask #3:

score: 0
Skipped