T1
根据题意,我们可以很容易得出结论:
1、将每个数质因子分解,每个数的贡献就等于它好质数的个数减去坏质数的个数;
2、用
g
[
i
]
g[i]
g[i]表示
g
c
d
(
a
[
1
]
,
a
[
2
]
,
.
.
.
,
a
[
i
]
)
gcd(a[1],a[2],...,a[i])
gcd(a[1],a[2],...,a[i]),
g
[
i
]
g[i]
g[i]的贡献仍可用上述方法计算,然后贪心,若
g
[
i
]
<
0
g[i] <0
g[i]<0则消去,否则不管。
注意:这个过程应从后往前进行,因为
g
[
i
]
g[i]
g[i]一定是
g
[
1
]
,
g
[
2
]
,
.
.
.
,
g
[
i
−
1
]
g[1],g[2],...,g[i-1]
g[1],g[2],...,g[i−1]的因数,如果从前往后消的话,消完第一个后面的
g
[
i
]
g[i]
g[i]就都等于1了。
#include<bits/stdc++.h>
using namespace std;
int read()
{
int i=0;char ch;
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) {i=i*10+ch-'0';ch=getchar();}
return i;
}
const int N=1e5+5;
bitset<1000000005>s;
int n,m,ans,tot,a[2005],tag[N],p[N],g[2005];
int gcd(int x,int y) {return !y ? x : gcd(y,x%y);}
int divide(int x)
{
int ans=0;
for(int i=1;i<=tot&&p[i]*p[i]<=x;i++)
while(x%p[i]==0) ans+=s[p[i]] ? -1 : 1,x/=p[i];
if(x>1) ans+=s[x] ? -1 : 1;
return ans;
}
int main()
{
freopen("cup.in","r",stdin);
// freopen("cup.out","w",stdout);
n=read();m=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++) s[read()]=1;
for(int i=1;i<=n;i++) g[i]=gcd(g[i-1],a[i]);
tag[1]=1;
for(int i=2;i<=N;i++)
{
if(tag[i]==1) continue;
p[++tot]=i;
for(int j=2;j<=N/i;j++)
tag[j*i]=1;
}
for(int i=1;i<=n;i++) ans+=divide(a[i]);
int cnt=1,now=0;
for(int i=n;i>=1;i--)
{
g[i]/=cnt;
now=divide(g[i]);
if(now<0) ans+=i*(-now),cnt*=g[i];
}
printf("%d",ans);
return 0;
}
T2
这是一道雅礼的模拟题,改了一下描述。
首先用两个小根堆分别求出两种机器处理完
1
,
2
,
.
.
.
,
l
1,2,...,l
1,2,...,l 个物品的时间,然后逆序相加,取
m
a
x
max
max即为答案。
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long
int read()
{
int i=0;char ch;
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) {i=i*10+ch-'0';ch=getchar();}
return i;
}
int l,n,m;
ll L[1000005],ans,a[100005],b[100005];
priority_queue<pair<ll,int> >qa,qb;
int main()
{
freopen("farewell.in","r",stdin);
// freopen("farewell.out","w",stdout);
l=read();n=read();m=read();
for(int i=1;i<=n;i++) a[i]=read(),qa.push(mp(-a[i],i));
for(int i=1;i<=m;i++) b[i]=read(),qb.push(mp(-b[i],i));
for(int i=1;i<=l;i++)
{
int id=qa.top().second;ll t=-qa.top().first;qa.pop();
L[i]=t;
qa.push(mp(-a[id]-t,id));
}
for(int i=l;i>=1;i--)
{
int id=qb.top().second;ll t=-qb.top().first;qb.pop();
qb.push(mp(-b[id]-t,id));
ans=max(ans,L[i]+t);
}
printf("%lld",ans);
return 0;
}
T3
先挖个坑,等弄懂了再来写(逃…