QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#402088 | #8543. Periodic Sequence | oscaryang | AC ✓ | 980ms | 7972kb | C++20 | 2.4kb | 2024-04-29 21:14:41 | 2024-04-29 21:14:41 |
Judging History
answer
#include<bits/stdc++.h>
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;
mt19937 gen(time(0));
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x;
}
const int N = 2e5 + 5, B = 450;
int MOD = 998244353;
// CALC
inline void inc (int &x, int y) { x += y - MOD; x += (x >> 31) & MOD; }
inline int qpow (int a, int b) { int res = 1; for(; b; b >>= 1, a = 1ll * a * a % MOD) if(b & 1) res = 1ll * res * a % MOD; return res; }
inline int qinv (int a) { return qpow(a, MOD - 2); }
struct mint {
int x;
mint (int ix = 0) { x = ix % MOD; if(x < 0) x += MOD; }
mint operator += (mint a) { inc (x, a.x); return a; }
mint operator -= (mint a) { inc (x, MOD - a.x); return a; }
mint operator *= (mint a) { x = 1ll * x * a.x % MOD; return a; }
mint friend operator + (mint a, mint b) { a += b; return a; }
mint friend operator - (mint a, mint b) { a -= b; return a; }
mint friend operator * (mint a, mint b) { a *= b; return a; }
} fc[N], ifc[N], pw[N], ans[N];
inline void init (int n) {
fc[0] = ifc[0] = pw[0] = 1;
rep (i, 1, n) fc[i] = fc[i - 1] * i, pw[i] = pw[i - 1] * 2;
ifc[n] = qinv (fc[n].x);
lep (i, n - 1, 1) ifc[i] = ifc[i + 1] * (i + 1);
}
inline mint C (int a, int b) { return a < b ? 0 : fc[a] * ifc[b] * ifc[a - b]; }
inline void prework (int n) {
// k <= B
rep (i, 1, B) {
vc <mint> dp (n + 1, 0), s (n + 1, 0);
dp[0] = s[0] = 1;
rep (j, 1, n) {
dp[j] = s[j - 1] - (j > i ? s[j - i - 1] : 0);
if (j >= i) ans[j] += dp[j - i];
s[j] = s[j - 1] + dp[j];
}
}
rep (i, 1, n) ans[i] += ans[i - 1];
// k > B
mint val;
rep (x, 0, B - 1) {
vc <mint> dp (n + 1, 0);
for (int y = 0; y + (x + 1) * (B + 1) <= n; y ++) {
val = C (y, x) * pw[y - x];
if (x & 1) dp[y + (x + 1) * (B + 1)] -= val;
else dp[y + (x + 1) * (B + 1)] += val;
}
rep (i, 1, n) {
if (i > x) dp[i] += dp[i - x - 1];
ans[i] += dp[i];
}
}
}
signed main() {
int n = read (); MOD = read ();
init (2e5);
prework (n);
rep (i, 1, n) printf ("%d%c", ans[i].x, " \n"[i == n]);
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 6924kb
input:
5 1000000007
output:
1 3 6 11 19
result:
ok 5 number(s): "1 3 6 11 19"
Test #2:
score: 0
Accepted
time: 934ms
memory: 7972kb
input:
200000 567894337
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 195106662 344669981 35619335 477103886 79913732 147415830 329955039 273123672 546045352 337527455 443978690 4597...
result:
ok 200000 numbers
Test #3:
score: 0
Accepted
time: 9ms
memory: 6932kb
input:
2000 1000000009
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 480458646 875091002 588152874 869906045 159506110 218346934 346224469 716986623 864678016 300921504 68...
result:
ok 2000 numbers
Test #4:
score: 0
Accepted
time: 980ms
memory: 7964kb
input:
200000 998244853
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 482213802 878601314 596928654 887457605 196364386 290308330 486636949 990790959 401755743 350504783 12...
result:
ok 200000 numbers
Test #5:
score: 0
Accepted
time: 961ms
memory: 7816kb
input:
200000 1000000009
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 480458646 875091002 588152874 869906045 159506110 218346934 346224469 716986623 864678016 300921504 68...
result:
ok 200000 numbers
Test #6:
score: 0
Accepted
time: 4ms
memory: 6892kb
input:
1 998244853
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 455ms
memory: 7344kb
input:
114514 1009999999
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 763000999 470458656 855091022 538152924 769906145 959506319 818347343 556225268 166988182 844681063 390927468 51...
result:
ok 114514 numbers
Test #8:
score: 0
Accepted
time: 951ms
memory: 7824kb
input:
199998 500000003
output:
1 3 6 11 19 33 57 100 177 317 573 1045 1919 3547 6592 12311 23091 43479 82153 155715 295983 564049 1077399 2062310 3955185 7598755 14622317 28179337 54379519 105071497 203254163 393607533 263000996 480458649 375091005 88152886 369906072 159506173 218347057 346224709 216987088 364678928 300923295 688...
result:
ok 199998 numbers
Extra Test:
score: 0
Extra Test Passed