提交时间:2024-04-28 21:08:37
运行 ID: 28696
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int,int> #define lc(x) (x<<1) #define rc(x) (x<<1|1) #define p1(x) x.first #define p2(x) x.second int n; int a[200300]; const int M=998244353; int f[200030][2][2]; inline void add(int &x,int y){ x+=y; if(x>=M)x-=M; } signed main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); ios::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; int res=0; for(int c=31;c>=0;c--){ int un=1ll<<c; memset(f,0,sizeof(f)); f[0][0][0]=1; int ct=0; for(int i=1;i<=n;i++){ int p = a[i]&(un-1); p++; if(a[i]&un){ ct++; for(int j=0;j<=1;j++) f[i][j][0]=p*f[i-1][j^1][0]%M, f[i][j][1]=( p*f[i-1][j^1][1]+un*f[i-1][j][1]%M+f[i-1][j][0])%M; } else{ for(int j=0;j<=1;j++) for(int k=0;k<=1;k++) f[i][j][k]=f[i-1][j][k]*p%M; } } add(res,f[n][0][1]); if(ct&1)break; if(c==0)add(res,1); } cout<<res<<endl; return 0; } /* */