QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#426743#8543. Periodic SequenceNaganohara_YoimiyaAC ✓540ms5392kbC++141.7kb2024-05-31 19:13:362024-05-31 19:13:38

Judging History

你现在查看的是最新测评结果

  • [2024-05-31 19:13:38]
  • 评测
  • 测评结果:AC
  • 用时:540ms
  • 内存:5392kb
  • [2024-05-31 19:13:36]
  • 提交

answer

#include<bits/stdc++.h>

#define ll long long
#define mk make_pair
#define fi first
#define se second

using namespace std;

inline int read(){
	int x=0,f=1;char c=getchar();
	for(;(c<'0'||c>'9');c=getchar()){if(c=='-')f=-1;}
	for(;(c>='0'&&c<='9');c=getchar())x=x*10+(c&15);
	return x*f;
}

int mod=998244353;
int ksm(int x,ll y,int p=mod){
	int ans=1;y%=(p-1);
	for(int i=y;i;i>>=1,x=1ll*x*x%p)if(i&1)ans=1ll*ans*x%p;
	return ans%p;
}
int inv(int x,int p=mod){return ksm(x,p-2,p)%p;}
mt19937 rnd(time(0));
int randint(int l,int r){return rnd()%(r-l+1)+l;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void Mod(int &x){if(x>=mod)x-=mod;}
int cmod(int x){if(x>=mod)x-=mod;return x;}

template<typename T>void cmax(T &x,T v){x=max(x,v);}
template<typename T>void cmin(T &x,T v){x=min(x,v);}

const int N=3e5+5;
const int B=450;
int n,f[N],ans[N];

void ins_1(int k){
	memset(f,0,sizeof(int)*(n+1));
	f[k]=1;
	for(int i=k+1;i<=n;i++)f[i]=cmod(cmod(f[i-1]+f[i-1])+mod-f[i-k-1]);
	for(int i=k;i<=n;i++)add(ans[i],f[i]);
	// cout<<"ins k = "<<k<<" f = ";for(int i=1;i<=n;i++)cout<<f[i]<<" ";puts("");
}
void ins_2(int j){
	int w=1;if(j&1)w=mod-1;
	// cout<<"ins j = "<<j<<" f = ";for(int i=1;i<=n;i++)cout<<f[i]<<" ";puts("");
	for(int i=j+B*(j+1);i<=n;i+=j+1)add(ans[i],w);
}
void Div(){
	for(int i=1;i<=n;i++)add(ans[i],cmod(ans[i-1]+ans[i-1]));
}

signed main(void){

#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif

	n=read(),mod=read();
	for(int j=B;j>=0;j--)ins_2(j),Div();
	// cout<<"now ans = ";for(int i=1;i<=n;i++)cout<<ans[i]<<" ";puts("");
	for(int k=1;k<B;k++)ins_1(k);
	for(int i=1;i<=n;i++)cout<<ans[i]<<" \n"[i==n];

	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3760kb

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: 539ms
memory: 5324kb

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: 6ms
memory: 3840kb

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: 540ms
memory: 5380kb

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: 535ms
memory: 5392kb

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: 0ms
memory: 3700kb

input:

1 998244853

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 310ms
memory: 4648kb

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: 539ms
memory: 5360kb

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