QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406642#8543. Periodic SequencexiaolangWA 337ms45840kbC++142.4kb2024-05-07 15:41:042024-05-07 15:41:05

Judging History

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

  • [2024-05-07 15:41:05]
  • 评测
  • 测评结果:WA
  • 用时:337ms
  • 内存:45840kb
  • [2024-05-07 15:41:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
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{
	int cc[N];
	void mul(vector<pair<int,int> > a,vector<pair<int,int> > b){
		int lena=a.size();
		int lenb=b.size();
		for(int i=0;i<=n;i++){
			cc[i]=0;
		}
		for(int i=0;i<lena;i++){
			for(int j=0;j<lenb;j++){
				anss[a[i].first+b[j].first]=(anss[a[i].first+b[j].first]+a[i].second*b[j].second)%MOD;
			}
		}
	}
	vector<pair<int,int> > mulinv(vector<pair<int,int> > x){
		int xlen=x.size();
		for(int i=0;i<=n;i++){
			cc[i]=0;
			tar[i]=0;
		}
		tar[0]=1;
		vector<pair<int,int> >ans;
		for(int i=0;i<=n;i++){
			if(cc[i]==tar[i])continue;
			else{
				cnt++;
				int nowc=(cc[i]-tar[i]+MOD)%MOD;
				ans.push_back(make_pair(i,nowc));
				for(int j=0;j<xlen;j++){
					cc[i+x[j].first]=(cc[i+x[j].first]+nowc*x[j].second)%MOD;
				}
			}
		}
		return ans;
	}
	vector<int> div(vector<int> c){/* /(2x-1) */
		vector<int>ans;
		ans.clear();
		int len=c.size();
		for(int i=0;i<len-1;i++){
			int t=(MOD-c[i])%MOD;
			ans.push_back(t);
			c[i+1]=(c[i+1]-2*t+MOD+MOD)%MOD;
		}
		return ans;
	}
};
using namespace Polynomial;
vector<pair<int,int> > fz;
vector<pair<int,int> > fm;
struct Addition{
	int t,xmi,c;
}add[N*10];
bool cmp(Addition x,Addition y){
	return x.t>y.t;
}
int maxdep=0;
int addlen=0;
signed main(){
	//freopen("1.txt","r",stdin);
	//freopen("1.out","w",stdout);
	int tim1=clock();
	scanf("%lld%lld",&n,&MOD);
	int B=max(sqrt(n)/10,2.0);
	for(int i=1;i<=B;i++){
		fz.clear();
		fz.push_back(make_pair(i,MOD-1));
		fm.clear();
		fm.push_back(make_pair(0,MOD-1));
		fm.push_back(make_pair(1,2));
		fm.push_back(make_pair(i+1,MOD-1));
		mul(fz,mulinv(fm));
	}
	int tim3=clock();
	for(int i=1;i<=B;i++){
		for(int j=B+1;j*i-1<=n;j++){
			add[++addlen]=(Addition){i,j*i+i-1,-1};
			maxdep=max(maxdep,i);
		}
	}
	//int tim4=clock();
	//cout<<tim4-tim3<<"\n";
	vector<int>ans(n+1000);
	int nowadd=1;
	for(int i=maxdep;i>=1;i--){
		while(add[nowadd].t>=i){
			ans[add[nowadd].xmi]=(ans[add[nowadd].xmi]+add[nowadd].c)%MOD;
			nowadd++;
		}
		ans=div(ans);
	}
	//int tim4=clock();
	//cout<<tim3-tim1<<"\n";
	int tot=0;
	for(int i=1;i<=n;i++){
		cout<<(ans[i]+anss[i])%MOD<<" ";
	}
	cout<<"\n";
	//int tim2=clock();
	//cout<<tim2-tim1<<"\n";
	return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9924kb

input:

5 1000000007

output:

1 3 6 11 19 

result:

ok 5 number(s): "1 3 6 11 19"

Test #2:

score: -100
Wrong Answer
time: 337ms
memory: 45840kb

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:

wrong answer 91st numbers differ - expected: '225408361', found: '225408363'