标签:复杂 load and spl 详细 play tchar png lin
\[ \texttt{Description} \]
\[ \texttt{Solution} \]
\(a = 0, b = 0, c = 1, d = 1\) ;
\(a = 0, b = 1, c = 0, d = 0\) ;
\(a = 0, b = 1, c = 0, d = 1\) ;
\(a = 0, b = 1, c = 1, d = 0\) ;
\(a = 1, b = 0, c = 0, d = 0\) ;
\(a = 1, b = 0, c = 0, d = 1\) ;
\(a = 1, b = 0, c = 1, d = 0\) ;
\(a = 1, b = 1, c = 0, d = 0\) ;
\(a = 1, b = 1, c = 0, d = 1\) ;
\(a = 1, b = 1, c = 1, d = 0\) 。
时间复杂度 \(\text{O(32n)}\) 。
\[ \texttt{Code} \]
#include<cstdio>
#include<iostream>
#define RI register int
using namespace std;
namespace IO
{
static char buf[1<<20],*fs,*ft;
inline char gc()
{
if(fs==ft)
{
ft=(fs=buf)+fread(buf,1,1<<20,stdin);
if(fs==ft)return EOF;
}
return *fs++;
}
#define gc() getchar()
inline int read()
{
unsigned int x=0,f=1;char s=gc();
while(s<'0'||s>'9')s=gc();
while(s>='0'&&s<='9')x=x*10+s-'0',s=gc();
return x*f;
}
}using IO::read;
const int N=500100;
int n;
int a[N];
unsigned int cnt[33][2];
unsigned int ans;
int main()
{
n=read();
for(RI i=1;i<=n;i++)
a[i]=read();
for(RI i=1;i<=n;i++)
for(RI j=0;j<32;j++)
cnt[j][(a[i]>>j)&1]++;
for(RI i=0;i<32;i++)
{
unsigned int c=0;
c+=cnt[i][0]*cnt[i][0]*cnt[i][1]*cnt[i][1];
c+=cnt[i][0]*cnt[i][1]*cnt[i][0]*cnt[i][0];
c+=cnt[i][0]*cnt[i][1]*cnt[i][0]*cnt[i][1];
c+=cnt[i][0]*cnt[i][1]*cnt[i][1]*cnt[i][0];
c+=cnt[i][1]*cnt[i][0]*cnt[i][0]*cnt[i][0];
c+=cnt[i][1]*cnt[i][0]*cnt[i][0]*cnt[i][1];
c+=cnt[i][1]*cnt[i][0]*cnt[i][1]*cnt[i][0];
c+=cnt[i][1]*cnt[i][1]*cnt[i][0]*cnt[i][0];
c+=cnt[i][1]*cnt[i][1]*cnt[i][0]*cnt[i][1];
c+=cnt[i][1]*cnt[i][1]*cnt[i][1]*cnt[i][0];
ans+=c*(1<<i);
}
printf("%u\n",ans);
return 0;
}
\[ \texttt{Thanks} \ \texttt{for} \ \texttt{watching} \]
标签:复杂 load and spl 详细 play tchar png lin
原文地址:https://www.cnblogs.com/cjtcalc/p/12318151.html