Solution P3791
晕,位运算尽然要写 1ll << s。
- 题意:
给定
- 分析
考虑换个枚举顺序,变成对于每个不同的
因为涉及到位运算,所以考虑拆位,然后发现很想数位 dp,但偏偏 dp 不了。于是我们来拆分一下数位 dp 的具体过程,其中很关键的参量就是
于是我们枚举一个
于是我们得出了一种可行的做法:枚举
设
复杂度
- code
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
using namespace std;
namespace IO{
char ibuf[(1 << 20) + 1], *iS, *iT;
#if ONLINE_JUDGE
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline long long read () {
reg char ch = gh();
reg long long x = 0;
reg char t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? -x : x;
}
inline void write(long long x) {
if (x < 0) {
x = ~(x - 1);
putchar('-');
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
}
using IO::read;
using IO::write;
const int N = 80, mod = 998244353;
int n, m, ct, A, B, X, a[N], b[N], x[N], mi[N], h[N], ans;
__gnu_pbds::gp_hash_table <int, int> sd;
int D (int x) {
if (!(~x) || !x) return 0;
if (sd.find(x) != sd.end()) return sd[x];
int res = 0;
for (int l = 1, r; l <= x; l = r + 1) {
r = x / (x / l);
res = (res + (r - l + 1) % mod * (x / l) % mod) % mod;
}
return sd[x] = res;
}
signed main () {
A = read() + 1, B = read() + 1, X = read();
for (; A; A >>= 1) a[++n] = A & 1;
for (; B; B >>= 1) b[++m] = B & 1;
for (; X; X >>= 1) x[++ct] = X & 1;
mi[0] = 1; for (int i = 1; i < N; i++) mi[i] = mi[i - 1] * 2 % mod;
for (int i = max(max(n, m), ct); i; i--) h[i] = h[i + 1] + ((long long)(a[i] ^ b[i] ^ x[i]) << (i - 1));
for (int i = 1; i <= n; i++) {
if (!a[i]) continue;
for (int j = 1; j <= m; j++) {
if (!b[j]) continue;
int s = max(i, j), t = min(i, j), H = h[s] ^ (1ll << (s - 1));
if (s == t) H ^= (1ll << (s - 1));
ans = (ans + (D(H + (1ll << (s - 1)) - 1) - D(H - 1) + mod) % mod * mi[t - 1] % mod) % mod;
}
}
write(ans);
}