2019年杭州师范大学第十二届程序设计竞赛 H:Little Sub and Counting(简单数学题)

Little Sub and Counting

【题目】

Little Sub and Counting 

Time Limit:  1 s      Memory Limit:   256 MB

Submission:1587     AC:150     Score:100.00

Submit Codes

Description

Little Sub likes Math. Now he has a simple counting problem for you.
Given an positive integer sequence A, for each Ai, Please calculate how many elements Aj in the sequence satisfied Ai^Aj > Aj^Ai.

Input

The first line contains one positive integer n(1 ≤ n ≤ 100000).

The following line contains n positive integers Ai(1 ≤ Ai ≤ 2^31 − 1).

Output

Please output n integer in one line and separate them by a single space. The ith integer indicates the answer concerning Ai.

Author

CHEN, Jingbang

【题解】

我们可以发现,1没有满足条件的可能,1对任意其他数都满足;2只有在aj大于4的时候满足,2只对aj=3满足;2和大于3的数对3满足;大于n的数对n满足。所以我们只需要排序二分计算符合要求的个数即可。

【代码】

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    ll a[100005],b[100005];
    int c[5]={0};
    int n; scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        b[i]=a[i];
        if(a[i]==1) c[1]++;
        else if(a[i]==2) c[2]++;
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        if(a[i]==1) printf("0");
        else if(a[i]==2) printf("%d",c[1]+n-(lower_bound(b,b+n,5)-b));
        else if(a[i]==3) printf("%d",c[1]+c[2]+n-(lower_bound(b,b+n,a[i]+1)-b));
        else printf("%d",c[1]+n-(lower_bound(b,b+n,a[i]+1)-b));
        printf(i==n-1?" ":" ");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值