第三种
2025-11-19 19:16:59
发布于:福建
#include<bits/stdc++.h>
using namespace std;
#define int unsigned
const int N=1e6+5;
vector<int>qr[N];
int l[N5],ans[N5],a[N],b[N],c[N],d[N],f[N],g[N],h[N],n,m,t[N];
int gcd(int x,int y)
{
if(!y)
return x;
return gcd(y,x%y);
}
int read()
{
int s=0;
char ch=getchar();
while(ch<'0'||ch>'9')
ch=getchar();
while(ch>='0'&&ch<='9')
s=s*10+ch-48,ch=getchar();
return s;
}
signed main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
a[i]=read();
for(int i=1;i<=n;i++)
b[i]=read();
for(int i=1;i<=n;i++)
c[i]=read(),t[i]=1;
for(int i=1;i<=m;i++)
l[i]=read(),qr[read()].push_back(i);
for(int i=1;i<=n;i++)
{
int ls=0;
for(int j=i-1;j;j--)
{
if((a[j]&a[i])==a[j]&&(b[j]|b[i])==b[j]&&c[i]%c[j]==0)
ls=j,j=1;
}
for(int j=ls+1;j<=i;j++)
{
if(j^i)
{
f[j]+=(i-t[j])*a[j]*b[j]*c[j];
a[j]&=a[i];
b[j]|=b[i];
c[j]=gcd(c[j],c[i]);
}
g[j]=g[j-1]+f[j];
h[j]=h[j-1]+a[j]*b[j]*c[j];
d[j]=d[j-1]+(t[j]=i)*a[j]*b[j]c[j];
}
for(int j=0;j<qr[i].size();j++)
{
int l=::l[qr[i][j]];
ans[qr[i][j]]=g[i]-g[l-1]+(i+1)(h[i]-h[l-1])-d[i]+d[l-1];
}
}
for(int i=1;i<=m;i++)
printf("%u\n",ans[i]);
}
这里空空如也







有帮助,赞一个