QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#729668 | #6655. 巧克力 | PlentyOfPenalty# | AC ✓ | 510ms | 3716kb | C++20 | 2.5kb | 2024-11-09 17:35:40 | 2024-11-09 17:35:42 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) begin(x), end(x)
#ifdef memset0
#define log(...) fprintf(stderr, __VA_ARGS__)
#else
#define endl '\n'
#define log(...) (void(0))
#endif
using namespace std;
using ll = long long;
using lf = long double;
using ull = unsigned long long;
const int B = 61;
// const int B = 3;
const int mod = 1e9 + 7;
int T;
ll n, m, S;
int f[B + 5][2][3][3], g[B + 5][2][3];
void Upd(int &x, int y) { (x += y) >= mod ? x -= mod : 0; }
int Solve(ll x, ll xs) {
for (int i = 0; i <= B; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l) f[i][j][k][l] = 0;
f[0][0][1][1] = 1;
int nb, w;
for (int i = 0; i < B; ++i) {
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 3; ++k)
for (int l = 0; l < 3; ++l)
if (f[i][j][k][l]) {
// log("F %d %d %d %d=%d\n", i, j, k, l, f[i][j][k][l]);
for (int v = 0; v < 2; ++v)
for (int a = 0, b = (((xs >> i) & 1) ^ v); a < 2; ++a, b ^= 1) {
nb = (a ^ b ^ j);
w = (a + b + j > 1);
Upd(f[i + 1][w][v == nb ? k : (v ? 0 : 2)][v == ((x >> i) & 1) ? l : (v ? 2 : 0)], f[i][j][k][l]);
}
}
}
// log("F=%d+%d\n", f[B][0][0][1], f[B][0][0][0]);
return (f[B][0][0][1] + f[B][0][0][0]) % mod;
}
int Calc(ll x, ll xs) {
if (!x) return 0;
xs ^= x;
// log("Calc %lld %lld\n", x, xs);
int nb, w;
for (int i = 0; i <= B; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 3; ++k) g[i][j][k] = 0;
g[0][0][1] = 1;
for (int i = 0; i < B; ++i) {
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 3; ++k)
if (g[i][j][k]) {
// log("G %d %d %d=%d\n", i, j, k, g[i][j][k]);
for (int a = 0, b = ((xs >> i) & 1); a < 2; ++a, b ^= 1) {
nb = (a ^ b ^ j);
w = (a + b + j > 1);
Upd(g[i + 1][w][((x >> i) & 1) == nb ? k : (nb ? 2 : 0)], g[i][j][k]);
}
}
}
// log("G=%d\n", g[B][0][0]);
return g[B][0][0];
}
int main() {
#ifdef memset0
freopen("K.in", "r", stdin);
#endif
cin.tie(0)->sync_with_stdio(0);
cin >> T;
while (T--) {
cin >> n >> m;
if (!n && !m) {
cout << "0\n";
continue;
}
S = ((n + 1 >> 1) & 1);
for (int i = 1; i < B; ++i) {
if (((n >> i) & 1) && !(n & 1)) S |= (1ll << i);
}
S ^= m;
log("S=%lld\n", S);
cout << (Solve(n, S) + Calc(m, S)) % mod << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 510ms
memory: 3716kb
input:
50000 0 0 0 1 0 2 0 3 0 4 0 5 1 0 1 1 1 2 1 3 1 4 1 5 2 0 2 1 2 2 2 3 2 4 2 5 3 0 3 1 3 2 3 3 3 4 3 5 4 0 4 1 4 2 4 3 4 4 4 5 5 0 5 1 5 2 5 3 5 4 5 5 0 2000000013 3 2000000013 960420868510113883 392659194919473988 668803384430801620 162045456939453012 617795168362576047 722239203838631701 6050650100...
output:
0 1 1 2 2 3 1 0 2 2 2 2 2 1 1 0 4 4 0 4 4 6 2 3 2 2 2 4 0 5 5 0 6 5 7 6 0 0 617401866 87835503 788974705 719403921 388746468 343575572 346563231 107105273 892988359 21085898 256773311 736064559 221068497 268198252 311484988 140174338 95593482 477651660 154447963 420109896 648989232 806537128 7685205...
result:
ok 50000 numbers