以下这份代码并没有过。但感觉没有问题。不是蜜汁WA就是蜜汁T。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int mod = ;
const int N = , K = ;
int i;
int P = , G = , g[K+], ng[K+], inv[N+];
ll A[N*+], B[N*+];
ll pow(ll a, int n){
ll ans = ;
while(n){
if(n&)
ans = ans*a%P;
a = a*a%P;
n >>= ;
}
return ans;
}
void NTT(ll*a,int n,int t){
for(int i=,j=;i<n-;i++){
for(int s=n;j^=s>>=,~j&s;);
if(i<j)swap(a[i], a[j]);
}
for(int d=;(<<d)<n;d++){
int m=<<d,m2=m<<;
ll _w=pow(G, (P-)>>(d+));
if(t != ) _w = pow(_w, P-);
for(int i=;i<n;i+=m2)for(ll w=,j=;j<m;j++){
ll&A=a[i+j+m],&B=a[i+j],t=w*A%P;
A=B-t;if(A<)A+=P;
B=B+t;if(B>=P)B-=P;
w=w*_w%P;//////////////////////
}
}
if(t==-)for(int i=,j=pow(n, P-);i<n;i++)a[i]=a[i]*j%P;
} /*****************另一份NTT模板
void change (ll y[], int len) {
for(int i = 1, j = len / 2; i < len - 1; i++) {
if(i < j) swap(y[i], y[j]);
int k = len / 2;
while(j >= k) {
j -= k;
k /= 2;
}
if(j < k) j += k;
}
}
void ntt(ll y[], int len, int on) {
change (y, len);
for(int h = 2; h <= len; h <<= 1) {
ll wn = pow(G, (mod-1)/h);
if(on == -1) wn = pow(wn, mod-2);
for(int j = 0; j < len; j += h) {
long long w = 1;
for(int k = j; k < j + h / 2; k++) {
long long u = y[k];
long long t = w * y[k + h / 2] % mod;
y[k] = (u + t) % mod;
y[k+h/2] = (u - t + mod) % mod;
w = w * wn % mod;
}
}
}
if(on == -1) {
long long t = pow (len, mod - 2);
for(int i = 0; i < len; i++)
y[i] = y[i] * t % mod;
}
}
***************************/ int a[N];
int pow2[N], r[N], f[N], F[N]; int main(){
// freopen("in", "r", stdin);
// freopen("outd", "w", stdout);
// for(g[K]=pow(G,(P-1)/N),ng[K]=pow(g[K],P-2),i=K-1;~i;i--)
// g[i]=(ll)g[i+1]*g[i+1]%P, ng[i]=(ll)ng[i+1]*ng[i+1]%P;
for(inv[]=inv[]=,i=;i<N;i++) inv[i]=(ll)(P-inv[P%i])*(P/i)%P; for(f[]=f[]=r[]=r[]=pow2[]=, i=pow2[]=; i < N; i++){
r[i] = (ll)inv[i]*r[i-]%P;
f[i] = (ll)i*f[i-]%P;
pow2[i] = (pow2[i-]<<)%P;
} int t, ca = , n; scanf("%d", &t);
while(t--){
scanf("%d", &n);
for(i = ; i <= n; i++) scanf("%d", a+i);
sort(a+, a+n+, greater<int>() ); memset(B, , sizeof(B));
memset(A, , sizeof(A));
for(i = ; i <= n; i++){
B[i-] = (ll)f[i-]*pow2[n-i]%P*a[i]%P;
A[i-] = r[n-i];
} int len = ;
while(len <= n+n) len <<= ;
NTT(B, len, ), NTT(A, len, );
for(int i = ; i < len; i++)
A[i] = B[i]*A[i]%P;
NTT(A, len, -); for(int i = ; i <= n; i++){
F[i] = A[n-+i]*(ll)r[i-]%P+F[i-];
if(F[i] >= P) F[i] %= P;
printf("%d ", F[i]);
}
puts("");
}
return ;
}
以上代码蜜汁T,NTT()换成ntt()后蜜汁WA。
和AC代码对拍很久也没看出什么问题。