题目
题面值得学习一下
多维前缀和:
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
for (k=1;k<=n;k++) a[i][j][k]+=a[i][j][k-1];
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
for (k=1;k<=n;k++) a[i][j][k]+=a[i][j-1][k];
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
for (k=1;k<=n;k++) a[i][j][k]+=a[i-1][j][k];
Code
#include<bits/stdc++.h>
using namespace std;
int i,n,s[1<<20],j;
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
int x=0,fl=1;char ch=gc();
for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
return x*fl;
}
inline void wri(int a){if(a>=10)wri(a/10);putchar(a%10|48);}
inline void wln(int a){if(a<0)a=-a,putchar('-');wri(a),puts("");}
int main(){
n=rd();
for (i=0;i<n;i++) s[i]=rd();
for (j=1;j<n;j<<=1)//枚举维度
for (i=0;i<n;i++)//枚举所有数
if (i&j) s[i]+=s[i^j];
for (i=0;i<n;i++) wln(s[i]);
}