#include<bits/stdc++.h>
using namespace std;
void simulate(long long x, long long l, long long n) {
vector<long long> s1, s2;
bool s1_inv = 0;
while (x) {
if (!s1.size()) s1.push_back(0);
if (!s2.size()) s2.push_back(0);
s2.push_back(s1.back() ^ s1_inv);
s1.pop_back();
s1_inv ^= 1;
if (s2.back() > l) {
cout << (s2.back() & 1);
--x;
} else {
s2.back() += 2ll * n;
s1.push_back(s2.back() ^ s1_inv);
s1.push_back(s2.back() ^ s1_inv);
s2.pop_back();
if (s2.size()) s2.pop_back();
}
}
}
const long long l2_inf = 62;
int main() {
int ntest; cin >> ntest;
while (ntest--) {
long long x, l, n; cin >> x >> l >> n;
long long mul = l / n;
mul += 1 + (~mul & 1);
long long l2_period = min(l2_inf, mul / 2 + 1);
--x;
x %= 1ll << l2_period;
cout << mul * n + (__builtin_popcountll(x) & 1) << '\n';
}
// cout << endl;
// simulate(1000, 9, 2);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
760 KB |
Output is correct |
2 |
Correct |
45 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
6392 KB |
Output is correct |
2 |
Correct |
565 ms |
8024 KB |
Output is correct |