zoukankan      html  css  js  c++  java
  • codeforces 691F Couple Cover(暴力预处理)

    题意:

    给你一个长度为n的序列,m个询问,每次学问一个数

    让你回答序列中乘积不小于它的数对有多少对

    思路:

    预处理当前序列中不大于当前值的数对有多少,然后用总数减去他的前一个就是答案了

    /* ***********************************************
    Author        :devil
    ************************************************ */
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <cmath>
    #include <stdlib.h>
    using namespace std;
    typedef long long LL;
    const int inf=0x3f3f3f3f;
    const int mod=1e9+7;
    const int N=3e6;
    int n,m,ma;
    LL cnt[N],sum[N];
    int main()
    {
        //freopen("in.txt","r",stdin);
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&m);
            cnt[m]++;
            ma=max(ma,m);
        }
        for(int i=1;i<=ma;i++)
            for(int j=1;j<=ma;j++)
            {
                if(1ll*i*j>N) break;
                if(i==j) sum[i*j]+=cnt[i]*(cnt[j]-1);
                else sum[i*j]+=cnt[i]*cnt[j];
            }
        for(int i=2;i<=N;i++)
            sum[i]+=sum[i-1];
        scanf("%d",&m);
        LL tmp=1ll*n*(n-1);
        while(m--)
        {
            scanf("%d",&ma);
            printf("%I64d
    ",tmp-sum[ma-1]);
        }
        return 0;
    }
  • 相关阅读:
    堆排序
    深入理解创建类设计模式(Creational Patterns)
    (Head First)设计模式基础
    SpringMVC中的适配器模式应用
    软工团队任务
    visio画UML用例图
    安卓架构设计
    结对项目编程之代码进展
    工大助手(爬虫——查成绩部分)
    设计模式
  • 原文地址:https://www.cnblogs.com/d-e-v-i-l/p/5697233.html
Copyright © 2011-2022 走看看