QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#533381#8543. Periodic Sequencechenxinyang2006WA 986ms11856kbC++202.8kb2024-08-25 21:14:242024-08-25 21:14:25

Judging History

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

  • [2024-08-25 21:14:25]
  • 评测
  • 测评结果:WA
  • 用时:986ms
  • 内存:11856kb
  • [2024-08-25 21:14:24]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;

template <class T>
void chkmax(T &x,T y){
	if(x < y) x = y;
}

template <class T>
void chkmin(T &x,T y){
	if(x > y) x = y;
}

inline int popcnt(int x){
	return __builtin_popcount(x);
}

inline int ctz(int x){
	return __builtin_ctz(x);
}

int mod;
template <class ADD>
inline void add(ADD &x,ADD y){
	x += y;
	if(x >= mod) x -= mod;
}

template <class SUB>
inline void sub(SUB &x,SUB y){
	x -= y;
	if(x < 0) x += mod;
}

ll power(ll p,int k = mod - 2){
	ll ans = 1;
	while(k){
		if(k % 2 == 1) ans = ans * p % mod;
		p = p * p % mod;
		k /= 2;
	}
	return ans;
}

__int128 mu;
namespace barrett {
	inline ll reduce(ll x) {
    	ll r = x - (mu * x >> 64) * mod;
    	return r >= mod ? r - mod : r;
    }
  	inline void setmod(ll mod) {
    	mu = -1ull / mod;
  	}
}
using namespace barrett;
int n,B;
ll dp[200005],ans[200005],P[200005];
ll C[200005];

ll cof[200005];
int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	scanf("%d%d",&n,&mod);
	B = sqrt(n);
	setmod(mod);
	P[0] = 1;
	rep(i,1,n){
		P[i] = P[i - 1];
		add(P[i],P[i - 1]);
	}
	rep(i,1,B){
		dp[0] = 1;
		rep(j,1,n){
			dp[j] = dp[j - 1];
			add(dp[j],dp[j - 1]);
			if(j >= i + 1) sub(dp[j],dp[j - i - 1]);
		}
		rep(j,0,n - i) add(ans[i + j],dp[j]);
	}	
	rep(i,0,n) C[i] = 1;
	int idx = 0;
/*	rep(i,0,n){
		idx = i + B + 1;
		rep(j,0,min(i,n / B)){
			if(idx > n) break;
//			printf("%d->%d %lld %lld\n",j,idx,C[j],P[i - j]);
			if(j & 1) sub(delta[j + 1][idx],reduce(C[j] * P[i - j]));
			else add(delta[j + 1][idx],reduce(C[j] * P[i - j]));
			idx += B + 1;
		}
		per(j,min(i + 1,n / B),1) add(C[j],C[j - 1]);
	}*/
	rep(j,0,n / B){
		idx += B + 1;
		fill(cof,cof + n + 1,0);
		rep(i,j,n){
			if(idx + i > n) break;
			add(cof[idx + i],reduce(C[i] * P[i - j]));
		}
		rep(i,0,n - j - 1) add(cof[i + j + 1],cof[i]);
		rep(i,0,n){
			if(j & 1) sub(ans[i],cof[i]);
			else add(ans[i],cof[i]);
		}
		rep(i,1,n) add(C[i],C[i - 1]);
		per(i,n,1) C[i] = C[i - 1];
	}
/*	rep(i,1,n / B){
//		rep(j,0,n) printf("%lld ",delta[i][j]);
//		printf("\n");
		rep(j,0,n - i) add(delta[i][i + j],delta[i][j]);
		rep(j,0,n) add(ans[j],delta[i][j]);			
	}*/
	rep(i,1,n) printf("%lld ",ans[i]);
	printf("\n");
	cerr << clock() << endl;
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 8116kb

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: 986ms
memory: 11856kb

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 1346th numbers differ - expected: '285668959', found: '285668960'