求助玄学问题
查看原帖
求助玄学问题
91127
_5011_楼主2021/2/17 17:08

洛谷上A了,本地Windows样例输出随机数

不知道是UB还是什么原因,求助/kk

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;

#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;

inline int qread() {
	register char c = getchar();
	register int x = 0, f = 1;
	while (c < '0' || c > '9') {
		if (c == '-') f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 3) + (x << 1) + c - 48;
		c = getchar();
	}
	return x * f;
}

inline int Abs(const int& x) {return (x > 0 ? x : -x);}
inline int Max(const int& x, const int& y) {return (x > y ? x : y);}
inline int Min(const int& x, const int& y) {return (x < y ? x : y);}

const long long mod = 998244353, g = 3, invg = 332748118;
int n, m, x[800005], y[800005], r, l, rev[800005];

inline long long Power(long long x, long long y) {
	long long ans = 1;
	while (y) {
		if (y & 1) ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

struct Poly {
	long long* a;
	int n;
	inline void NTT(int type) {
		for (int i = 0;i < n;i++) {
			if (i < rev[i]) swap(a[i], a[rev[i]]);
		}
		long long W = 1;
		for (int i = 1;i < n;i <<= 1) {
			W = Power((type > 0 ? g : invg), (mod - 1) / (i << 1));
			//cout << W << endl;
			for (int j = 0;j < n;j += (i << 1)) {
				long long w = 1;
				for (int k = 0;k < i;k++) {
					long long v1 = a[j + k], v2 = w * a[j + i + k] % mod;
					a[j + k] = (v1 + v2) % mod;
					a[j + i + k] = (v1 - v2 + mod) % mod;
					w = w * W % mod;
				}
			}
		}
	}
};
Poly f;

inline void Inv(int n, Poly f, Poly g) {
	if (n == 1) {
		g.a[0] = Power(f.a[0], mod - 2);
		return;
	}
	Inv(n + 1 >> 1, f, g);
	Poly a;
	a.n = 1;
	int l = 0;
	while (a.n < 2 * n) {
		a.n <<= 1;
		l++;
	}
	a.a = new long long [a.n + 5];
	memset(a.a, 0, sizeof(a.a));
	for (int i = 0;i < n;i++) a.a[i] = f.a[i];
	for (int i = 1;i < a.n;i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);
	g.n = a.n;
	printf("n=%d\n", n);
	a.NTT(1);
	g.NTT(1);
	for (int i = 0;i < a.n;i++) g.a[i] = (2 + mod - a.a[i] * g.a[i] % mod) % mod * g.a[i] % mod;
	g.NTT(-1);
	long long invn = Power(g.n, mod - 2);
	for (int i = 0;i < n;i++) g.a[i] = (g.a[i] * invn % mod + mod) % mod;
	for (int i = n;i < g.n;i++) g.a[i] = 0;
	for (int i = 0;i < n;i++) printf("%lld ", g.a[i]); puts("");
	delete [] a.a;
}

inline void Read() {
	f.n = qread();
	f.a = new long long [4 * f.n + 5];
	for (int i = 0;i < f.n;i++) f.a[i] = qread();
}

inline void Solve() {
	Poly g;
	g.a = new long long [4 * f.n];
	memset(g.a, 0, sizeof(g.a));
	Inv(f.n, f, g);
	for (int i = 0;i < f.n;i++) printf("%lld ", g.a[i]);
}

int main() {
	Read();
	Solve();
	#ifndef ONLINE_JUDGE
	while (1);
	#endif
	return 0;
}
2021/2/17 17:08
加载中...