QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720354 | #8543. Periodic Sequence | konyakest | WA | 785ms | 5336kb | C++17 | 2.0kb | 2024-11-07 12:06:13 | 2024-11-07 12:06:13 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i,j,k) for(auto i=j;i<=(decltype(i))k;i++)
#define x first
#define y second
#define exec(...) [&](){__VA_ARGS__}()
#define endl '\n'
#define os ostream
#define pb push_back
#define view(x) begin(x),end(x)
#define lambda [&]
using namespace std;
using ll=long long;
template<typename T>void ckmin(T& x,T y){x=min(x,y);}
template<typename T>void ckmax(T& x,T y){x=max(x,y);}
#ifdef DEBUG
template<typename T1,typename T2>os& operator<<(os&,pair<T1,T2>);
template<typename T,typename=decltype(T().begin()),typename=enable_if_t<!is_same_v<decay_t<T>,string>>>os& operator<<(os& out,T x){auto n=0u;out<<"{";for(auto i:x) out<<i<<(++n==x.size()?"":",");return out<<"}";}
template<typename ...T>os& operator<<(os& out,tuple<T...> x){return apply(lambda(T... x){auto n=0u;out<<"{";((out<<x<<(++n==sizeof...(T)?"":",")),...);},x),out<<"}";}
template<typename T1,typename T2>os& operator<<(os& out,pair<T1,T2> x){return out<<tuple(x);}
#define debug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = "<<std::make_tuple(__VA_ARGS__)<<endl
#else
#define debug(...) (void)0
#endif
const int maxn=3e5+5,B=450;
int ans[maxn],f[maxn],n,mod;
#if 1
int cmod(int x){if(x>=mod)x-=mod;return x;}
void add(int &x,int v){x+=v;if(x>=mod)x-=mod;}
void ge(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("");
}
#else
void ge(int k){
memset(f,0,sizeof f);
f[k]=1,ans[k]++;
F(i,k+1,n) f[i]=(2ll*f[i-1]+mod-f[i-k-1])%mod,(ans[i]+=f[i])%=mod;
}
#endif
void le(int k){
int w=(k&1?mod-1:1);
for(int i=B*(k+1);i<=n;i+=k+1) (ans[i]+=w)%=mod;
F(i,1,n) ans[i]=(ans[i]+2ll*ans[i-1])%mod;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>mod;
for(int i=B;i>=0;i--) le(i);
F(i,1,B-1) ge(i);
F(i,1,n) cout<<ans[i]<<" ";
cout<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
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: 785ms
memory: 5336kb
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 900th numbers differ - expected: '381269230', found: '381269229'