QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#533386#8543. Periodic Sequencechenxinyang2006AC ✓989ms11812kbC++202.9kb2024-08-25 21:23:132024-08-25 21:23:13

Judging History

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

  • [2024-08-25 21:23:13]
  • 评测
  • 测评结果:AC
  • 用时:989ms
  • 内存:11812kb
  • [2024-08-25 21:23:13]
  • 提交

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){
		idx += B + 1;
		if(idx > n) break;
		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,0,n) printf("%lld ",cof[i]);
//		printf("\n");
		rep(i,1,n) add(C[i],C[i - 1]);
		per(i,n,1) C[i] = C[i - 1];
		C[0] = 0;
//		rep(i,0,n) printf("%lld ",C[i]);
	}
/*	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; 
}

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

详细

Test #1:

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

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: 976ms
memory: 11800kb

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

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: 983ms
memory: 11636kb

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: 975ms
memory: 11812kb

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: 10000kb

input:

1 998244853

output:

1 

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 419ms
memory: 11064kb

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: 989ms
memory: 11804kb

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