zoukankan      html  css  js  c++  java
  • Bad Prices ( Codeforces Round #582 )

    Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for nn last days: a1,a2,,ana1,a2,…,an, where aiai is the price of berPhone on the day ii.

    Polycarp considers the price on the day ii to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if n=6n=6 and a=[3,9,4,6,7,5]a=[3,9,4,6,7,5], then the number of days with a bad price is 33 — these are days 22 (a2=9a2=9), 44 (a4=6a4=6) and 55 (a5=7a5=7).

    Print the number of days with a bad price.

    You have to answer tt independent data sets.

    Input

    The first line contains an integer tt (1t100001≤t≤10000) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.

    Each input data set consists of two lines. The first line contains an integer nn (1n1500001≤n≤150000) — the number of days. The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1061≤ai≤106), where aiai is the price on the ii-th day.

    It is guaranteed that the sum of nn over all data sets in the test does not exceed 150000150000.

    Output

    Print tt integers, the jj-th of which should be equal to the number of days with a bad price in the jj-th input data set.

    Example
    input
    Copy
    5
    6
    3 9 4 6 7 5
    1
    1000000
    2
    2 1
    10
    31 41 59 26 53 58 97 93 23 84
    7
    3 2 1 2 3 4 5
    
    output
    Copy
    3
    0
    1
    8
    2

    分析:逆序遍历,如果当前值的大于当前值最小值,就计数++,否则,更新当前最小值



    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    using namespace std;
    #define pq priority_queue<int>
    #define pql priority_queue<ll>
    #define pqn priority_queue<node>
    #define v vector<int>
    #define vl vector<ll>
    #define lson rt<<1, l, m  
    #define rson rt<<1|1, m+1, r
    #define read(x) scanf("%d",&x)
    #define lread(x) scanf("%lld",&x);
    #define pt(x) printf("%d
    ",(x))
    #define yes printf("YES
    ");
    #define no printf("NO
    ");
    #define gcd __gcd
    #define cn cin>>
    #define ct cout<<
    #define ed <<endl;
    #define ok return 0 ;
    #define over cout<<endl;
    #define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
    #define input(k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i] ; }
    #define mem(s,t) memset(s,t,sizeof(s))
    #define re return 0;
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define mod(x) ((x)%9973)
    #define test cout<<"     ++++++      "<<endl; 
    typedef long long ll;
    const int N=150000+5;
    const int maxn=10000+5;
    const int len = 1e5+5;
    typedef struct node
    {
        int x,y,ankle,T;
    }node;
    node dp[len]; 
    double getlen(node xx,node yy) { return ( (xx.x-yy.x)*(xx.x-yy.x) +(xx.y-yy.y)*(xx.y-yy.y) ); } //计算两点间距离 
    int a[N];
    int main()
    {
        int n,k,t;
        for(cin>>t;t;t--)
        {
            k=0;
            cin>>n;
            input(n);
            int mx=a[n];
            for(int i=n-1;i>=1;i--)
            {
                if(a[i]>mx) k++;
                else mx=a[i];
            }
            cout<<k<<endl;
        }
        ok;
    }

     

    所遇皆星河
  • 相关阅读:
    js 作用域
    js 实现二级联动
    JavaScript 基础(四)
    JavaScript 基础(三)
    数据库事务的基本概念
    二进制安装 kubernetes 1.12(五)
    二进制安装 kubernetes 1.12(四)
    二进制安装 kubernetes 1.12(三)
    二进制安装 kubernetes 1.12(二)
    Centos 7.x 安装 Docker-ce
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11447228.html
Copyright © 2011-2022 走看看