H.Little Sub and Counting

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

题解:xy>yx -->取ln --> ylnx>xlny-->x/lnx<y/lny,以此为依据排序统计个数即可.
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
const int N=1e5+5;
using namespace std;
typedef long long ll;
double a[N];
double b[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf",&a[i]),a[i]=1.0*a[i]/log(a[i]),b[i]=a[i];
    sort(b+1,b+1+n);
    for(int i=1;i<=n-1;i++){
        printf("%d ",n-(upper_bound(b+1,b+1+n,a[i])-b)+1);
    }
    printf("%d ",n-(upper_bound(b+1,b+1+n,a[n])-b)+1);
    //cout << "Hello world!" << endl;
    return 0;
}

posted @ 2019-03-18 00:55  _yjun  阅读(403)  评论(0编辑  收藏  举报