QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#464188 | #8834. Formal Fring | Crying | AC ✓ | 67ms | 26316kb | C++14 | 1.5kb | 2024-07-05 21:45:58 | 2024-07-05 21:45:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e6+10,MAXM = 25,M = 20,mod = 998244353;
int addv(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
int subv(int x,int y){return (x>=y)?(x-y):(x-y+mod);}
void add(int& x,int y){x = addv(x,y);}
void sub(int& x,int y){x = subv(x,y);}
int qpow(int a,int n){
int res = 1; a%=mod;
while(n){
if(n&1)res = 1ll*res*a%mod;
n>>=1; a = 1ll*a*a%mod;
}
return res;
}
int qinv(int a){return qpow(a,mod-2);}
//
int n,f[MAXN],sum[MAXN],g[MAXM][MAXN],h[MAXM];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>n;
f[0] = 1; sum[0] = 1;
for(int i=1;i<=n;i++){
f[i] = sum[i/2];
sum[i] = addv(sum[i-1],f[i]);
}
//
g[1][1] = 1;
for(int i=2;i<=M;i++){
for(int j=1;j<(1<<(i-1));j++){
int w = g[i-1][j];
if(!w)continue;
add(g[i][j*2+1],w);
}
for(int j=1<<i;j>=2;j--)add(g[i][j],g[i][j+2]);
}
for(int i=1;i<=M;i++)for(int j=1;j<=1<<i;j++)add(h[i],g[i][j]);
//printf("get %d,%d\n",g[2][1],g[2][3]);
//
for(int i=1;i<=n;i++){
//if(i!=3)continue;
int ans = 0;
int r=0,j=i,cnt=0; while((1<<r) <= i)r++; r--;
for(int x=r;x>=0;x--)if(i>>x&1){
j ^= 1<<x; cnt++;
//printf("x:%d j:%d with %d,%d\n",x,j,h[cnt],f[j]);
add(ans,1ll*h[cnt]*f[j]%mod);
}else break;
cout<<ans<<" ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 10ms
memory: 18064kb
input:
10
output:
1 1 2 1 1 3 6 1 1 2
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 4ms
memory: 18040kb
input:
70
output:
1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6
result:
ok 70 numbers
Test #3:
score: 0
Accepted
time: 67ms
memory: 26316kb
input:
1000000
output:
1 1 2 1 1 3 6 1 1 2 2 5 5 11 26 1 1 2 2 4 4 6 6 11 11 16 16 27 27 53 166 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 37 37 48 48 64 64 80 80 107 107 134 134 187 187 353 1626 1 1 2 2 4 4 6 6 10 10 14 14 20 20 26 26 36 36 46 46 60 60 74 74 94 94 114 114 140 140 166 166 203 203 240 240 288 288 336 336 400 ...
result:
ok 1000000 numbers
Extra Test:
score: 0
Extra Test Passed