QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345829#8308. Artifactsblack_moonrise#Compile Error//C++144.8kb2024-03-07 15:31:162024-03-07 15:31:17

Judging History

你现在查看的是最新测评结果

  • [2024-03-07 15:31:17]
  • 评测
  • [2024-03-07 15:31:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;

typedef long long ll;
const int mod = 998244353;
const int maxsize = 270111;
const int proot = 3;

ll qpow(ll x, ll y) {
	ll ret = 1;
	while(y) {
		if(y&1) ret = ret * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ret;
}

struct ntt {
	int n, M, w_pre[maxsize], inv[maxsize];
	ntt() {
		M = 1;
		while(M*2<maxsize) M <<= 1;
		int w = qpow(proot, (mod - 1) / M);
		w_pre[0] = 1;
		for(int i=1; i<=M; i++) w_pre[i] = 1ll * w_pre[i-1] * w % mod;
		inv[1] = 1;
		for(int i=2; i<maxsize; i++) inv[i] = mod - 1ll * inv[mod % i] * (mod / i) % mod;
	}
	void FFTinit(int sz) {
		n = 1;
		while(n < sz) n <<= 1;
		assert(n <= M);
	}
	void FFT(int a[], int coef) {
		typedef unsigned long long ull;
		const ull mod2 = 1ull * mod * mod;
		static ull na[maxsize];
		for(int i=0, j=0; i<n; i++) {
			na[j] = a[i] < 0 ? (a[i] + mod) : a[i];
			for(int l=n>>1; (j^=l) < l; l>>=1) continue;
		}
		static int w[maxsize];
		for(int l=1; l<n; l<<=1) {
			int l2 = l + l, u = M / l2;
			if(coef == 1) {
				for(int j=0, t=0; j<l; j++, t+=u) w[j] = w_pre[t];
			}
			else {
				for(int j=0, t=M; j<l; j++, t-=u) w[j] = w_pre[t];
			}
			for(int i=0; i<n; i+=l2) {
				for(int j=0; j<l; j++) {
					ull tmp = na[i+j+l] % mod * w[j];
					na[i+j+l] = na[i+j] - tmp + mod2;
					na[i+j] += tmp;
				}
			}
			if(l == (1 << 8) || l == (1 << 16)) for(int i=0; i<n; i++) na[i] %= mod;
		}
		for(int i=0; i<n; i++) a[i] = 1ll * na[i] * mod * (coef == -1?inv[n]:1) % mod;
	}
	vector<int> multi(vector<int> &A, vector<int> &B, int N = -1) {
		if(N == -1) N = max(0, int(A.size() + B.size()) - 1);
		FFTinit(A.size() + B.size());
		static int a[maxsize], b[maxsize];
		for(int i=0; i<n; i++) a[i] = i < A.size() ? A[i] % mod : 0;
		for(int i=0; i<n; i++) b[i] = i < B.size() ? B[i] % mod : 0;
		FFT(a, 1);
		FFT(b, 1);
		for(int i=0; i<n; i++) a[i] = 1ll * a[i] * b[i] % mod;
		FFT(a, -1);
		vector<int> ret(N);
		for(int i=0; i<N; i++) ret[i] = a[i];
		return ret;
	}
} M1;
const int maxn = 100111;
int n, a[maxn];

typedef long long ll;
const int maxsize = 270111;
ll qpow (ll x, ll k, ll mod){return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1, mod)*(k&1?x:1)%mod;}
//NTT head - START
template <const int mod, const int proot> struct ntt {
	int n, M, w_pre[maxsize], inv[maxsize];
	ntt() {
		M = 1; while (M*2<maxsize) M <<= 1;
		int w = qpow(proot, (mod-1)/M, mod);
		w_pre[0] = 1;
		for (int i=1; i<=M; i++) w_pre[i] = 1ll*w_pre[i-1]*w%mod;
		inv[1] = 1;
		for (int i=2; i<maxsize; i++) inv[i] = mod-1ll*inv[mod%i]*(mod/i)%mod;
	}
	void FFTinit(int sz) {
		n = 1; while (n<sz) n <<= 1;
		assert(n<=M);
	}
	void FFT(int a[], int coef) {
		typedef unsigned long long ull;
		const ull mod2=1ull*mod*mod;
		static ull na[maxsize];
		for (int i=0, j=0; i<n; i++) {
			na[j] = a[i]<0? a[i]+mod: a[i];
			for (int l=n>>1; (j^=l)<l; l>>=1) continue;
		}
		static int w[maxsize];
		for (int l=1; l<n; l<<=1) {
			int l2=l+l, u=M/l2;
			if (coef==1) {
				for (int j=0, t=0; j<l; j++, t+=u) w[j] = w_pre[t];
			} else {
				for (int j=0, t=M; j<l; j++, t-=u) w[j] = w_pre[t];
			}
			for (int i=0; i<n; i+=l2) {
				for (int j=0; j<l; j++) {
					ull tmp = na[i+j+l]%mod*w[j];
					na[i+j+l] = na[i+j]-tmp+mod2;
					na[i+j] += tmp;
				}
			}
			if(l==(1<<8)||l==(1<<16)) for (int i=0; i<n; i++) na[i] %= mod;
		}
		for (int i=0; i<n; i++) a[i] = 1ll*na[i]%mod*(coef==-1?inv[n]:1)%mod;
	}
	vector<int> multi(vector<int> &A, vector<int> &B, int N=-1) {
		if (N==-1) N = max(0, int(A.size()+B.size())-1);
		FFTinit(A.size()+B.size());
		static int a[maxsize], b[maxsize];
		for (int i=0; i<n; i++) a[i] = i<A.size()? A[i]%mod: 0;
		for (int i=0; i<n; i++) b[i] = i<B.size()? B[i]%mod: 0;
		FFT(a,1), FFT(b,1);
		for (int i=0; i<n; i++) a[i] = 1ll*a[i]*b[i]%mod;
		FFT(a,-1);
		vector<int> ret(N);
		for (int i=0; i<N; i++) ret[i] = a[i];
		return ret; 
	}
};
ntt <998244353, 3> MS;
ntt <1004535809, 3> MS2;
ntt <2013265921, 31> MS3;


vector<int> calc(int l, int r) {
	if(l == r) {
		vector<int> ret;
		ret.push_back(0);
		ret.push_back(a[l]);
		return ret;
	}
	int mid = (l + r) / 2;
	vector<int> lv = calc(l, mid);
	vector<int> rv = calc(mid+1, r);
	return M1.multi(lv, rv);
}

int fac[maxn], invf[maxn];

void solve() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	vector<int> m = calc(1, n);
	int ans = 0;
	for(int i=0; i<=n; i++) {
		ans = (ans + 1ll * fac[i] * m[i]) % mod;
	}
	ans = 1ll * ans * invf[n] % mod;
	printf("%d\n", ans);
}

int main() {
	fac[0] = 1;
	for(int i=1; i<maxn; i++) fac[i] = 1ll * i * fac[i-1] % mod;
	invf[maxn-1] = qpow(fac[maxn-1], mod - 2);
	for(int i=maxn-1; i>=1; i--) invf[i-1] = 1ll * i * invf[i] % mod;
	int tc;
	scanf("%d", &tc);
	while(tc--) solve();
	return 0;
}

Details

answer.code:83:11: error: redefinition of ‘const int maxsize’
   83 | const int maxsize = 270111;
      |           ^~~~~~~
answer.code:7:11: note: ‘const int maxsize’ previously defined here
    7 | const int maxsize = 270111;
      |           ^~~~~~~
answer.code:86:50: error: ‘ntt’ is not a template
   86 | template <const int mod, const int proot> struct ntt {
      |                                                  ^~~
answer.code:20:8: note: previous declaration here
   20 | struct ntt {
      |        ^~~
answer.code:141:1: error: ‘ntt’ is not a template
  141 | ntt <998244353, 3> MS;
      | ^~~
answer.code:142:1: error: ‘ntt’ is not a template
  142 | ntt <1004535809, 3> MS2;
      | ^~~
answer.code:143:1: error: ‘ntt’ is not a template
  143 | ntt <2013265921, 31> MS3;
      | ^~~
answer.code: In function ‘void solve()’:
answer.code:162:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  162 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:163:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  163 |         for(int i=1; i<=n; i++) scanf("%d", a+i);
      |                                 ~~~~~^~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:179:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  179 |         scanf("%d", &tc);
      |         ~~~~~^~~~~~~~~~~