codeforces 691F Couple Cover 暴力

分析:开一个300w的数组,统计,然后nlogn统计每个值在在序对第一个出现有多少种情况

时间复杂度:O(nlogn) n在3e6数量级

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N  = 3e6;
const LL mod = 1e9+7;
LL n,m,sum[N+5],c[N+5];
int main(){
  scanf("%I64d",&n);
  int mx=0;
  for(int i=1;i<=n;++i){
    int x;scanf("%d",&x);++c[x];
    mx=max(x,mx);
  }
  for(int i=1;i<=mx;++i){
    for(int j=1;j<=mx;++j){
       if(1ll*i*j>N)break;
       if(i==j)sum[i*j]+=c[i]*(c[i]-1);
       else sum[i*j]+=c[i]*c[j];
    }
  }
  for(int i=1;i<=N;++i)sum[i]+=sum[i-1];
  scanf("%I64d",&m);
  while(m--){
    int p;
    scanf("%d",&p);
    printf("%I64d\n",n*(n-1)-sum[p-1]);
  }
  return 0;
}
View Code

 

转载于:https://www.cnblogs.com/shuguangzw/p/5674669.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值