QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759314 | #9701. Cat | thangthang | WA | 637ms | 3604kb | C++20 | 2.1kb | 2024-11-18 00:44:48 | 2024-11-18 00:44:49 |
Judging History
answer
// author : thembululquaUwU
// 3.9.2024
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
const int MaxN = 2e5;
const int mod = 1e9 + 7;
void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}
#define Mask(i) (1ll << (i))
#define Bit(x, i) ((x) >> (i) & 1ll)
#define bp __builtin_popcount
#define bpll __builtin_popcountll
void solve(){
ll L, R, S; cin >> L >> R >> S;
auto calc = [&](long long f) -> long long {
long long ans = 0;
for (int b = 0; b < 62; ++ b){
long long x = Mask(b);
if (!b){
ll g = f / 2;
if (g % 2 == 1) ans |= 1;
}
else {
ll g = f / x;
if (g % 2 == 1){
if ((f - g * x) % 2 == 1) ans |= x;
}
}
}
return ans;
};
ll xr = calc(R + 1) ^ calc(L);
if (xr <= S) cout << R - L + 1 << endl;
else {
ll ans = R - L + 1;
int x = 63 - __builtin_clzll(S);
if (Bit(L, x) || Bit(R, x)) ans = 1;
else {
long long tmp = Mask(x);
for (int b = x + 1; b < 62; ++ b) if (Bit(L, b)) tmp += Mask(b);
minl(ans, tmp - L + 1);
int p = -1;
for (int b = x + 1; b < 62; ++ b) if (Bit(R, b)){
p = b;
break;
}
tmp = Mask(p) - 1;
for (int b = p + 1; b < 62; ++ b) if (Bit(R, b)) tmp += Mask(b);
minl(ans, R - tmp + 1);
}
ans = R - L + 1 - ans;
if (!ans) cout << -1 << endl;
else cout << ans << endl;
}
}
int main(){
if (fopen("pqh.inp", "r")){
freopen("pqh.inp", "r", stdin);
freopen("pqh.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t = 1; cin >> t;
while (t --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 637ms
memory: 3604kb
input:
500000 28316250877914575 822981260158260522 1779547116602436425 335408917861648772 578223540024979445 74859962623690079 252509054433933447 760713016476190629 919845426262703496 522842184971407775 585335723211047202 148049062628894322 84324828731963982 354979173822804784 1001312150450968415 269587449...
output:
794665009280345948 242814622163330674 508203962042257183 62493538239639427 270654345090840803 376174809552329776 469882136957817192 42350729279043822 64865315101301174 697234070719324700 223517937810991678 -1 120906461794646288 463966315863716824 433607439314780607 450247658658833134 554193509807664...
result:
wrong answer 4th numbers differ - expected: '62493538239639426', found: '62493538239639427'