QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#533387 | #8543. Periodic Sequence | chenxinyang2006 | AC ✓ | 785ms | 11816kb | C++20 | 2.3kb | 2024-08-25 21:25:49 | 2024-08-25 21:25:49 |
Judging History
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(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,idx,n - j - 1) add(cof[i + j + 1],cof[i]);
if(j & 1) rep(i,idx,n) sub(ans[i],cof[i]);
else rep(i,idx,n) add(ans[i],cof[i]);
rep(i,1,n) add(C[i],C[i - 1]);
per(i,n,1) C[i] = C[i - 1];
C[0] = 0;
}
rep(i,1,n) printf("%lld ",ans[i]);
printf("\n");
cerr << clock() << endl;
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5996kb
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: 773ms
memory: 11740kb
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: 2ms
memory: 10152kb
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: 785ms
memory: 11816kb
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: 779ms
memory: 11664kb
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: 6064kb
input:
1 998244853
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 335ms
memory: 11016kb
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: 775ms
memory: 11644kb
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