AC题解
2023-07-16 16:32:20
发布于:广东
45阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN = 1 << 20 | 1;
inline char gc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) &&(ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? EOF : *ib++;
}
inline int read() {
char ch = gc();
int res = 0;
bool f = 1;
while (!isdigit(ch))
f ^= ch == '-', ch = gc();
while (isdigit(ch))
res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
return f ? res : -res;
}
inline ll readll() {
char ch = gc();
ll res = 0;
bool f = 1;
while (!isdigit(ch))
f ^= ch == '-', ch = gc();
while (isdigit(ch))
res = (res + (res << 2) << 1) + (ch ^ 48), ch = gc();
return f ? res : -res;
}
inline int readstring(char *s) {
int top = 0;
char ch = gc();
while (isspace(ch))
ch = gc();
while (!isspace(ch) && ch != EOF)
s[++top] = ch, ch = gc();
s[top + 1] = '\0';
return top;
}
template<typename tp>inline void chemx(tp &a, tp b) {
a = max(a, b);
}
template<typename tp>inline void chemn(tp &a, tp b) {
a = min(a, b);
}
int mod;
inline int add(int a, int b) {
return (a + b) >= mod ? (a + b - mod) : (a + b);
}
inline int dec(int a, int b) {
return (a < b) ? (a - b + mod) : (a - b);
}
inline int mul(int a, int b) {
static ll r;
r = (ll)a * b;
return (r >= mod) ? (r % mod) : r;
}
inline void Add(int &a, int b) {
a = (a + b) >= mod ? (a + b - mod) : (a + b);
}
inline void Dec(int &a, int b) {
a = (a < b) ? (a - b + mod) : (a - b);
}
inline void Mul(int &a, int b) {
static ll r;
r = (ll)a * b;
a = (r >= mod) ? (r % mod) : r;
}
inline int ksm(int a, int b, int res = 1) {
for (; b; b >>= 1, Mul(a, a))
(b & 1) && (Mul(res, a), 1);
return res;
}
inline int Inv(int x) {
return ksm(x, mod - 2);
}
inline int fix(ll x) {
x %= mod;
return (x < 0) ? x + mod : x;
}
cs int N = 500005, M = 305;
int n, k, f[N], ans[M], lim;
inline void mul(int k) {
for (int i = lim - 1; i >= k; i--)
Dec(f[i], f[i - k]);
for (int i = 1; i < lim; i++)
Add(f[i], f[i - 1]);
}
inline void div(int k) {
for (int i = lim - 1; i; i--)
Dec(f[i], f[i - 1]);
for (int i = k; i < lim; i++)
Add(f[i], f[i - k]);
}
int main() {
#ifdef Stargazer
freopen("lx.in", "r", stdin);
#endif
n = read(), k = read(), mod = read();
for (int i = 1; i <= n; i++)
lim += i - 1;
lim++;
f[0] = 1;
for (int i = 1; i <= n; i++)
mul(i);
for (int i = 1; i <= n; i++)
ans[i] = f[k];
for (int i = 1; i <= n; i++) {
div(i + 1);
for (int j = 1; j + i <= n; j++) {
if (k - i >= 0)
Add(ans[j], f[k - i]);
Add(ans[j + i], f[k]);
}
mul(i + 1);
}
for (int i = 1; i <= n; i++)
cout << ans[i] << " ";
return 0;
}
全部评论 1
好心人一生平安
2023-08-06 来自 河北
0
有帮助,赞一个