QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#846814 | #6655. 巧克力 | hhoppitree | AC ✓ | 1291ms | 3876kb | C++23 | 1.4kb | 2025-01-07 14:47:42 | 2025-01-07 14:47:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, P = 1e9 + 7;
void add(int &x, int y) {
((x += y) >= P) && (x -= P);
}
int f[61][3][2][2];
int calc(long long v, long long n) {
if (n < 0) return 0;
memset(f, 0, sizeof(f));
f[0][0][0][0] = 1;
for (int i = 0; i < 60; ++i) {
for (int j = 0; j <= 2; ++j) {
for (int k = 0; k < 2; ++k) {
for (int l = 0; l < 2; ++l) {
if (!f[i][j][k][l]) continue;
for (int a = 0; a < 2; ++a) {
for (int b = 0; b < 2; ++b) {
for (int c = 0; c < 2; ++c) {
int t = j + a + b + c;
if ((a ^ (t & 1) ^ c) != ((v >> i) & 1)) continue;
add(f[i + 1][t >> 1][k | b][((t & 1) == ((n >> i) & 1)) ? l : ((t & 1) > ((n >> i) & 1))], f[i][j][k][l]);
}
}
}
}
}
}
}
return f[60][0][1][0];
}
signed main() {
int T; scanf("%d", &T);
while (T--) {
long long n, m; scanf("%lld%lld", &n, &m);
long long v = (n % 4 == 3 ? 0 : (n % 4 == 0 ? n : (n % 4 == 1 ? 1 : n + 1))) ^ m;
printf("%lld\n", (0ll + calc(v, n) + calc(v, m) - calc(v, m - 1) + P) % P);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1291ms
memory: 3876kb
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