QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424271 | #8543. Periodic Sequence | Afterlife | AC ✓ | 1449ms | 182120kb | C++20 | 1.6kb | 2024-05-29 03:32:45 | 2024-05-29 03:32:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n , mod;
int ans[200005];
int a2[200005];
int g[200003];
int f[200005];
int f2[450][200005];
void upd(int &x,int y) {
x = (x + y) % mod;
}
int fpow(int a,int b) {
int ans = 1;
while(b) {
if(b & 1) ans = 1LL * ans * a %mod ;
a = 1LL * a * a %mod ; b >>= 1;
}
return ans;
}
int main() {
cin >> n >> mod;
int sq = sqrt(n);
for(int k = 1;k <= sq;k++) {
f[0] = 1;
ans[k] = (ans[k] + 1) % mod;
for(int i = 1 ; i <= n - k ; i++) {
if(i <= k) f[i] = (2LL * f[i - 1]) % mod;
else f[i] = (2LL * f[i - 1] - f[i - (k+1)] + mod) % mod;
ans[i + k] = (ans[i + k] + f[i]) % mod;
}
}
for(int k = sq + 1 ; k <= n;k++) {
for(int g = 0 ; g * (k + 1) + k <= n ; g++) {
/// x^k * (-x^(k+1))^g / (2x+1) ^ (g + 1)
// printf("upd %d %d : %d\n",g+1,k + g*(k+1) , (g & 1)) ;
upd(f2[g + 1][k + g * (k + 1)] , ((g & 1) ? mod - 1 : 1)) ;
}
}
int mxl = (n - (sq + 1)) / (sq + 2) + 1;
for(int i = mxl;i >= 1;i--) {
// for(int j = 0;j <= n;j++) printf("%d ",f2[i][j]) ; printf("\n");
for(int j = 0;j <= n;j++) a2[j] = (a2[j] + f2[i][j]) % mod ;
g[0] = a2[0] ;
for(int j = 1;j <= n;j++) {
g[j] = (a2[j] + 2LL * g[j - 1]) % mod;
}
for(int j = 0;j <= n;j++) a2[j] = g[j] ;
}
for(int i = 0;i <= n;i++) ans[i] = (ans[i] + a2[i] ) % mod;
for(int i = 1;i <= n;i++) {
cout << ans[i] <<' ' ;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
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: 1444ms
memory: 182120kb
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: 2ms
memory: 4056kb
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: 1432ms
memory: 181952kb
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: 1446ms
memory: 181984kb
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: 1ms
memory: 3752kb
input:
1 998244853
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 613ms
memory: 81808kb
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: 1449ms
memory: 181948kb
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