UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214936#3855. 好数132704606090187ms1192kbC++766b2024-11-24 10:53:052024-11-24 13:15:21

answer

#include <cstdio>
#include <iostream>
using namespace std;
int T;
long long l, r;
int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%lld%lld", &l, &r);
        long long ans = -1, val = 0ll;
        int cnt = 0;
        for (int i = 32; ~i && !(~ans); i--) {
            cnt += (l >> i & 1), val |= (l & (1ll << i));
            if ((r >> i & 1) && !(l >> i & 1)) {
                long long tmp = val | (1ll << i);
                if (cnt + 1 == i) {
                    if (tmp <= r) ans = tmp;
                } else if (cnt + 2 < i) {
                    tmp |= (1ll << cnt + 2);
                    if (tmp <= r) ans = tmp;
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}

详细

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

1
999995700 1000000000

output:

-1

result:

ok Accepted! >_<


Test #2:

score: -30
Wrong Answer
time: 36ms
memory: 1188kb

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: 30
Accepted
time: 32ms
memory: 1188kb

input:

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

output:

8388612
7337984
8255488
8124416
8378368
8353792
8321024
4192256
8250368
8315904
8348672
6284288
4178...

result:

ok Accepted! >_<


Test #14:

score: 0
Accepted
time: 26ms
memory: 1188kb

input:

100000
330807594 855120061
2739043 698283851
6893055 483485075
87223028 335275196
436165546 84345741...

output:

536870916
536870916
268435460
268435460
536870916
536870916
939524112
536870916
536870916
536870916
...

result:

ok Accepted! >_<


Test #15:

score: 0
Accepted
time: 29ms
memory: 1188kb

input:

100000
775803569 969702803
85461932 615601357
762866118 893251725
250087967 904974579
155037438 6394...

output:

805306376
536870916
805306376
536870916
536870916
536870916
671088648
805306376
536870916
671088648
...

result:

ok Accepted! >_<


Test #16:

score: 0
Accepted
time: 32ms
memory: 1192kb

input:

100000
130615964 543185019
196269565 471109044
219486005 225290312
698409571 899750338
411258373 754...

output:

536870916
268435460
222298144
805306376
536870916
134217732
234881040
536870916
268435460
805306376
...

result:

ok Accepted! >_<


Test #17:

score: -30
Wrong Answer
time: 32ms
memory: 1188kb

input:

100000
255723571 895551031
508758301 569794703
40263079 330048659
113440683 868414377
950208385 9778...

output:

536870916
536870916
268435460
536870916
973078560
536870916
117440528
536870916
536870916
536870916
...

result:

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


Subtask #3:

score: 0
Skipped