ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214933 | #3855. 好数 | 13270460609 | 0 | 126ms | 1192kb | C++ | 807b | 2024-11-24 10:14:21 | 2024-11-24 13:15:12 |
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--) {
if (!((l >> i & 1) ^ (r >> i & 1))) cnt += (l >> i & 1), val |= (l & (1ll << i));
else 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: 34ms
memory: 1192kb
input:
100000 7857167 7862247 8344618 8348655 8382478 8388566 8315927 8321011 8246290 8250342 8382480 83885...
output:
-1 8339968 -1 -1 8241664 -1 8373248 6275584 7848448 -1 7848448 7324160 8339968 7324160 -1 8370176 -1...
result:
wrong answer 8339968 is not in range [8344618, 8348655].
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: 29ms
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: -30
Wrong Answer
time: 31ms
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:
wrong answer 976045056 is not in range [976050374, 976053712].
Subtask #3:
score: 0
Skipped