QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#803377 | #8962. Immensely Long Expressions | panhuachao# | TL | 0ms | 0kb | C++14 | 2.4kb | 2024-12-07 17:00:59 | 2024-12-07 17:01:02 |
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll p = 998244353, pri_rt = 15311432, pri_irt = 469870224;
// pri_rt^{1<<23} = 1
ll rt, irt;
vector<ll> tmp;
void ntt(vector<ll>::iterator arr, int len, ll w){
// w^(len/2)=-1. ntt: w=g^?, inverse: w=g^-?
if(len == 1) return;
for(int i = 0; i < len; i++) tmp[i] = arr[i];
for(int i = 0; i < len; i++)
if(i%2) arr[i/2+len/2] = tmp[i];
else arr[i/2] = tmp[i];
ntt(arr, len/2, w*w%p); ntt(arr+len/2, len/2, w*w%p);
ll t = 1;
for(int i = 0; i < len/2; i++){
tmp[i] = (arr[i] + t * arr[i+len/2] % p) % p;
tmp[i+len/2] = (arr[i] - t * arr[i+len/2] % p + p) % p;
t = t * w % p;
}
for(int i = 0; i < len; i++) arr[i] = tmp[i];
return;
}
void solve(){
auto quickpow = [&](ll base, ll index){
ll res = 1;
while(index > 0){
if(index & 1) res = res * base % p;
base = base * base % p;
index >>= 1;
}
return res;
};
int n, m, k, l;
scanf("%d%d%d%d", &n, &m, &k, &l);
int len = 1;
while(len <= max(n*n,m*m))
len <<= 1;
len <<= 1;
vector<ll> cnt_ab(len, 0), cnt_cd(len, 0), cnt_sum(len, 0);
vector<ll> cnt_ef((max(k,l)<<1)+1, 0);
tmp.resize(len, 0);
for(int a = 0; a <= n; a++)
for(int b = 0; b <= n; b++)
cnt_ab[a*b]++;
for(int c = 0; c <= m; c++)
for(int d = 0; d <= m; d++)
cnt_cd[c*d]++;
rt = pri_rt, irt = pri_irt;
for(int i = len; i < (1<<23); i <<= 1)
rt = rt * rt % p, irt = irt * irt % p;
ntt(cnt_ab.begin(), len, rt);
ntt(cnt_cd.begin(), len, rt);
for(int i = 0; i <= len; i++)
cnt_sum[i] = cnt_ab[i] * cnt_cd[i] % p;
ntt(cnt_sum.begin(), len, irt);
for(int i = 0; i <= len; i++)
cnt_sum[i] = cnt_sum[i] * quickpow(len, p-2) % p;
int xor_mx = 0;
for(int e = 0; e <= k; e++)
for(int f = 0; f <= l; f++){
xor_mx = max(xor_mx, e^f);
cnt_ef[e^f]++;
}
// printf("%d\n", xor_mx);
ll ans = 0;
for(int i = 0; i <= n*n+m*m; i++){
ll c = 1;
for(int j = 0; j <= xor_mx; j++, c = c*(i+1)%p)
ans = (ans + cnt_sum[i]*cnt_ef[j] * c) % p;
}
printf("%lld\n", ans);
return;
}
int main(){
int t; scanf("%d", &t);
while(t--) solve();
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
7 1 3 5 7 9 998244353 111111111224317155