【链接】
51nod1674
【解题报告】
经典的分块题目。
因为对于一组数 a1,a2,a3,...,an 的按顺序 and 值是递减的, or 值是递增的,所以对于每个块最多有 2∗log2amax 种情况(还有需要注意的是处理一个新的块时要去重)。所以此题就可以用分块解决。
#include<cstdio>
#define LL long long
using namespace std;
const int maxn=100005,maxv=65,tt=1000000007;
int n,tot,ans,a[maxn];
struct wjd
{
int a,b,l;
}c[maxn];
inline char nc()
{
static char buf[100000],*l=buf,*r=buf;
if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
if (l==r) return EOF; return *l++;
}
inline int Read()
{
int res=0; char ch=nc();
while (ch<'0'||ch>'9') ch=nc();
while (ch>='0'&&ch<='9') res=(res<<3)+(res<<1)+ch-48,ch=nc();
return res;
}
void Updata(int x)
{
c[++tot]=(wjd){a[x],a[x],1};
for (int i=1; i<=tot; i++) c[i].a&=a[x],c[i].b|=a[x];
int now=tot; tot=1;
for (int i=2; i<=now; i++)
if (c[i].a==c[tot].a&&c[i].b==c[tot].b) c[tot].l+=c[i].l; else c[++tot]=c[i];
for (int i=1; i<=tot; i++) ans=(ans+(LL)c[i].a*c[i].b%tt*c[i].l%tt)%tt;
}
int main()
{
freopen("1674.in","r",stdin);
freopen("1674.out","w",stdout);
n=Read(); ans=tot=0;
for (int i=1; i<=n; i++) a[i]=Read();
for (int i=n; i; i--) Updata(i);
printf("%d\n",ans);
return 0;
}