Codeforces 691F Couple Cover

可以暴力预处理出每一种小于3000000的乘积有几种。询问的时候可以用总的方案减去比p小的有几种o(1)输出。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi = acos(-1.0), eps = 1e-8;
void File()
{
    freopen("D:\\in.txt", "r", stdin);
    freopen("D:\\out.txt", "w", stdout);
}
inline int read()
{
    char c = getchar();  while (!isdigit(c)) c = getchar();
    int x = 0;
    while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); }
    return x;
}

const int maxn=1000000+10;
int n,q;
LL a[maxn],c[3*maxn],f[3*maxn];

void init()
{
    for(LL i=1;i<=3000000;i++)
    {
        if(c[i]==0) continue;
        for(LL j=1;j<=i;j++)
        {
            if(c[j]==0) continue;
            if(i*j>3000000) break;
            if(i==j) f[i*j]=f[i*j]+c[i]*(c[j]-1);
            else f[i*j]=f[i*j]+2*c[i]*c[j];
        }
    }
    for(int i=2;i<=3000000;i++) f[i]=f[i]+f[i-1];
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); c[a[i]]++; }
    init();
    scanf("%d",&q);
    for(int i=1;i<=q;i++)
    {
        LL p; scanf("%lld",&p);
        printf("%lld\n",(LL)n*(n-1)-f[p-1]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/zufezzt/p/5706264.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值