zoukankan      html  css  js  c++  java
  • codeforce895B

    While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordered pairs of indexes (i, j) such that ai ≤ aj and there are exactly k integers y such that ai ≤ y ≤ aj and y is divisible by x.

    In this problem it is meant that pair (i, j) is equal to (j, i) only if i is equal to j. For example pair (1, 2) is not the same as (2, 1).

    Input

    The first line contains 3 integers n, x, k (1 ≤ n ≤ 105, 1 ≤ x ≤ 109, 0 ≤ k ≤ 109), where n is the size of the array a and x and k are numbers from the statement.

    The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.

    Output

    Print one integer — the answer to the problem.

    Example

    Input
    4 2 1
    1 3 5 7
    Output
    3
    Input
    4 2 0
    5 3 1 7
    Output
    4
    Input
    5 3 1
    3 3 3 3 3
    Output
    25

    Note

    In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).

    In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).

    In third sample every pair (i, j) is suitable, so the answer is 5 * 5 = 25.

    #include <cstdio>
    #include <iostream>
    #include <string.h>
    #include <cmath>
    #include <algorithm>
    
    #define LL long long
    using namespace std;
    
    LL a[100000+10];
    int main()
    {
        int n,x,k;
        LL result = 0;
        while(scanf("%d",&n)!=EOF)
        {
            scanf("%d%d",&x,&k);
            result = 0;
            for(int i=1;i<=n;i++)cin>>a[i];
            sort(a+1,a+n+1);
            for(int i=1;i<=n;i++)
            {
                LL l = max(a[i],(k+((a[i]-1)/x))*x);
                LL r = max(a[i],(k+1+((a[i]-1)/x))*x);
                //cout<<l;
                //printf("    ");
                //cout<<r<<endl;
                result += (lower_bound(a+1,a+n+1,r)-lower_bound(a+1,a+n+1,l));
            }
            printf("%lld
    ",result);
        }
    
        return 0;
    }
    //2   6 13   6-(3-1)
    //6 8 10 12
    //(k+((a[i]-1)/x))*x=a[j];
    //a[j]/x-(a[i]-1)/x == k+1?
  • 相关阅读:
    如何修改 WordPress 的默认 Gravatar 头像
    解决wordpress部分博客文章页面无法显示的问题
    git删除本地所有的更改
    C++ char数组和string类简单使用总结
    c++ 中关于int,unsigned int , short的关系与应用
    CentOS下,mysql服务启动失败
    通过日志动态查看正在执行的mysql语句
    mysql 处理数据库中的重复行
    Linux cp复制
    在myeclipse中使用查找功能
  • 原文地址:https://www.cnblogs.com/--lr/p/7922647.html
Copyright © 2011-2022 走看看