UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214934#3855. 好数132704606090280ms1192kbC++751b2024-11-24 10:51:252024-11-24 13:15:15

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; 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) {
                    if ((tmp | (1ll << cnt + 2)) <= r) ans = (tmp | (1ll << cnt + 2));
                }
            }
        }
        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: 38ms
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: 39ms
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: 50ms
memory: 1188kb

input:

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

output:

330825984
2739456
6897728
87223296
436166656
184620160
878068224
321881088
421956096
518016000
16218...

result:

ok Accepted! >_<


Test #15:

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

input:

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

output:

775946304
85462144
762872832
250089984
155042816
271468800
606281856
614896128
378332160
634552832
2...

result:

ok Accepted! >_<


Test #16:

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

input:

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

output:

130617856
196270080
219486720
698412032
411259136
25559616
209125888
229310976
254457856
677872128
4...

result:

ok Accepted! >_<


Test #17:

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

input:

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

output:

255789056
508765184
40263936
117440528
950211072
336073280
117278720
486799360
535764992
19333184
49...

result:

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


Subtask #3:

score: 0
Skipped