#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <vector>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
int T;
scanf("%d", &T);
while (T--) {
ull l, r, s;
scanf("%llu%llu%llu", &l, &r, &s);
if (l == r) {
if (s >= l || s >= r)
printf("1\n");
else
printf("-1\n");
}
else if (r - l + 1 == 2) {
if (s >= (r ^ l))
printf("2\n");
else if (s >= r || s >= l)
printf("1\n");
else
printf("-1\n");
}
else {
if ((r - l + 1) % 2 == 0) {
//长度偶
if (l % 2 == 0) {
//偶开始
ull tmp = (r - l + 1) / 2;
if (tmp % 2 == 0)
printf("%llu\n", r - l + 1);
else {
if (s >= 1)
printf("%llu\n", r - l + 1);
else {
//s==0
if (s >= (1 ^ (l + 1)) || s >= (1 ^ (r - 1)))
printf("%llu\n", r - l + 1 - 1);
else
printf("%llu\n", r - l + 1 - 2);
}
}
}
else {
//奇开始
ull tmp = (r - l + 1 - 2) / 2;
if (tmp % 2 == 0) {
if (s >= (r ^ l))
printf("%llu\n", r - l + 1);
else if (s >= r || s >= l)
printf("%llu\n", r - l + 1 - 1);
else
printf("%llu\n", r - l + 1 - 2);
}
else {
if (s >= 1) {
if (s >= (1 ^ r ^ l))
printf("%llu\n", r - l + 1);
else if (s >= (1 ^ r) || s >= (1 ^ l))
printf("%llu\n", r - l + 1 - 1);
else
printf("%llu\n", r - l + 1 - 2);
}
else {
//s==0
if (s >= (1 ^ l) || s >= (1 ^ r))
printf("%llu\n", r - l + 1 - 1);
else if (r - l + 1 - 2 - 2 > 0)
printf("%llu\n", r - l + 1 - 2 - 2);
else
printf("-1\n");
}
}
}
}
else {
//长度奇
if (l % 2 == 0) {
//偶开始
ull tmp = (r - l + 1 - 1) / 2;
if (tmp % 2 == 0) {
if (s >= r)
printf("%llu\n", r - l + 1);
else
printf("%llu\n", r - l + 1 - 1);
}
else {
if (s >= 1) {
if (s >= (1 ^ r))
printf("%llu\n", r - l + 1);
else
printf("%llu\n", r - l + 1 - 1);
}
else {
//s==0
if (s >= (1 ^ r))
printf("%llu\n", r - l + 1);
else if (r - l + 1 - 3 > 0)
printf("%llu\n", r - l + 1 - 3);
else
printf("-1\n");
}
}
}
else {
//奇开始
ull tmp = (r - l + 1 - 1) / 2;
if (tmp % 2 == 0) {
if (s >= l)
printf("%llu\n", r - l + 1);
else
printf("%llu\n", r - l + 1 - 1);
}
else {
if (s >= 1) {
if (s >= (1 ^ l))
printf("%llu\n", r - l + 1);
else
printf("%llu\n", r - l + 1 - 1);
}
else {
//s==0
if (s >= (1 ^ l))
printf("%llu\n", r - l + 1);
else if (r - l + 1 - 3 > 0)
printf("%llu\n", r - l + 1 - 3);
else
printf("-1\n");
}
}
}
}
}
}
return 0;
}
2019 ICPC アジア徐州 A - Cat Jisuanke- 42540
おすすめ
転載: blog.csdn.net/xukeke12138/article/details/110943095
おすすめ
ランキング