QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184624 | #4322. rsraogps / 雪に咲く花 | Lynkcat | AC ✓ | 0ms | 0kb | C++17 | 2.5kb | 2023-09-20 23:53:59 | 2023-09-20 23:53:59 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < unsigned int,unsigned int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define N 1000005
using namespace std;
char obuf[1 << 27], *o(obuf);
inline char gc(){static char buf[1<<23],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++;}
// #define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
void print(uint x) {
if (x > 9)
print(x / 10);
*o++ = x % 10 + '0';
}
unsigned int n,m,a[N],b[N],c[N],ans[N*5];
unsigned int prea[N],preb[N],sum[N],sb[N];
pair<pa,int> all[N*5],all1[N*5];
inline int gcd(int x,int y)
{
return (y==0)?x:gcd(y,x%y);
}
void BellaKira()
{
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();
// m=2;
for (int i=1;i<=m;i++)
{
int l=read(),r=read();
sum[r]++;
all[i]=mp(mp(r,l),i);
all1[i]=all[i];
}
for (int i=1;i<=n;i++)
sum[i]+=sum[i-1];
for (int i=1;i<=m;i++)
all[sum[all1[i].fi.fi]--]=all1[i];
poly g;
for (int i=1,pos=1;i<=n;i++)
{
int t=i;
for (int j=i-1;j>=1;j--)
{
int x=a[j]&a[i];
if (x==a[j]) break;
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
a[j]=x;
}
for (int j=i-1;j>=1;j--)
{
int x=b[j]|b[i];
if (x==b[j]) break;
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
b[j]=x;
}
int lst=-1;
for (int j=i-1;j>=1;j--)
{
if (lst!=c[j]&&c[i]%c[j]==0) break;
lst=c[j];
if (j<t) sb[j]+=(prea[j]-prea[j-1])*(i-1),t=j;
c[j]=gcd(c[j],c[i]);
}
for (int j=t;j<=i;j++)
{
int v=a[j]*b[j]*c[j];
sb[j]+=-v*(i-1);
prea[j]=prea[j-1]+v,
preb[j]=preb[j-1]+sb[j];
}
while (pos<=m&&all[pos].fi.fi==i)
{
int l=all[pos].fi.se,id=all[pos].se;
{
int A=prea[i]-prea[l-1];
int B=preb[i]-preb[l-1];
ans[id]+=A*i+B;
}
pos++;
}
}
for (int i=1;i<=m;i++) print(ans[i]),
*o++ = '\n';
fwrite(obuf, o - obuf, 1, stdout);
}
signed main()
{
int T=1;
while (T--)
{
BellaKira();
}
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
This is the input of the first test case.