QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#406674 | #8543. Periodic Sequence | xiaolang | AC ✓ | 2626ms | 9288kb | C++14 | 1.5kb | 2024-05-07 16:23:34 | 2024-05-07 16:23:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3e6+5;
int n,MOD;
int cc[N];
int anss[N];
int tar[N];
int inv[N];
int cnt=0;
namespace Polynomial{
vector<int> div(vector<int> c){/* /(2x-1) */
vector<int>ans;
ans.clear();
int len=c.size();
for(int i=0;i<len;i++){
int t=(MOD-c[i])%MOD;
ans.push_back(t);
if(i!=len-1)c[i+1]=((long long)c[i+1]-2*t+MOD+MOD)%MOD;
}
return ans;
}
void div2(vector<int> c,int p){/* /(-x^p+2x-1) */
int len=c.size();
for(int i=0;i<len;i++){
int t=(MOD-c[i])%MOD;
anss[i]=(anss[i]+t)%MOD;
if(i!=len-1)c[i+1]=((long long)c[i+1]-2*t+MOD+MOD)%MOD;
if(i+p<len)c[i+p]=(c[i+p]+t)%MOD;
}
}
};
using namespace Polynomial;
vector<int> fz;
int maxdep=0;
int addlen=0;
int main(){
//freopen("1.txt","r",stdin);
//freopen("1.out","w",stdout);
//int tim1=clock();
scanf("%d%d",&n,&MOD);
int B=pow(n,0.5);
fz.resize(n+2);
for(int i=1;i<=B;i++){
for(int j=0;j<=n;j++)fz[j]=((j==i)?(MOD-1):0);
div2(fz,i+1);
}
int tim3=clock();
vector<int>ans(n+500,0);
for(int i=n/B+1;i>=1;i--){
for(int j=B+1;j*i-1<=n;j++){
ans[j*i+i-1]=(ans[j*i+i-1]-1+MOD)%MOD;
}
ans=div(ans);
}
//int tim4=clock();
//cout<<tim4-tim3<<"\n";
//int tim4=clock();
//cout<<tim3-tim1<<"\n";
int tot=0;
for(int i=1;i<=n;i++){
//cout<<ans[i]<<" "<<anss[i]<<"\n";
cout<<(ans[i]+anss[i])%MOD<<" ";
}
cout<<"\n";
//int tim2=clock();
//cout<<tim2-tim1<<"\n";
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3992kb
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: 2626ms
memory: 9156kb
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: 4ms
memory: 3868kb
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: 2587ms
memory: 9288kb
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: 2581ms
memory: 9220kb
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: 3996kb
input:
1 998244853
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 1114ms
memory: 6320kb
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: 2604ms
memory: 9168kb
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