2019 Hangzhou Normal school race problem H: Little Sub and Counting

Question H: Little Sub and Counting
Time limit: 1 Sec Memory Limit: 256 MB
submit: 351 Resolution: 100
[submit] [state] [proposition man: admin]
Title Description
Little Sub likes Math Now he has a simple counting problem for. you.
the Given AN A positive Integer Sequence, for the each Ai, Aj Please Elements in the Calculate How MANY Sequence satisfi at The ED AiAj> Ajai.

输入
The first line contains one positive integer n(1 ≤ n≤100000).
The following line contains n positive integers Ai(1≤Ai≤231-1).

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

Sample input
replicate sample data
. 3
. 1 2. 5
sample output
021

Ideas; extrapolate from Ai = 2 start, Aj = 3,4,5,6 ..., then Ai = 3, Aj = 4,5,6 ... , you will find more than a few times to infer, in addition to 2 (from 2 5 starts), the other number from number start than his own big 1, have been satisfied Ai Aj > Aj Ai , according to Y = a X extrapolate, a function of the nature, (a + 1) B , and a (B + 1) , their growth rate is particularly big difference, especially when a lot of time b, but also be noted that the law does not meet the 1, sentence 3 special needs, because the two 3 <3 2 ,

#include<iostream>
#include<cstring>
#include<string.h>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int ddd = 0;
    scanf("%d", &n);
    int a[100005], b[100005];
    int flag = 0, flag2 = 0;
    for (int i = 0; i < n; i++)
    {
        int t;
        scanf("%d", &t); a[i] = t; b[i] = t;
        if (t == 1)flag++;
        if (t == 2)flag2++;
    }
    sort(b, b + n);
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 1)
        {
            if (ddd == 0)
            {
                ddd++;
                printf("0");
            }
            else
            printf(" 0");
        }
        else{
            int t;
            if (a[i] == 2){
                t = upper_bound(b + 0, b + n, 4) - b;
            }
            else{
                t = upper_bound(b + 0, b + n, a[i]) - b;
            }
            if (a[i] == 3){
                if (ddd == 0)
                {
                    cout << n-t+flag+flag2;
                    ddd++;
                }
                else
                    cout << " " << n - t + flag + flag2;
            }
            else
            {
                if (ddd == 0)
                {
                    cout << n - t + flag;
                    ddd++;
                }
                else
                    cout << " " << n - t + flag;
            }
        }
    }
    return 0;
}

Published 10 original articles · won praise 6 · views 1796

Guess you like

Origin blog.csdn.net/Kris_Kris/article/details/89814197