给出 n 个数,对于其中一个来说, 如果在其后出现比它小的数, 则该数为 Bad Prices ,问一共有几个Bad Princes
既然是在它后面比它小, 那只要从最后面找到一个最小的数, 如果 前面的数大于这个最小的数,则这个数就是一个 Bad girl :)
所以 倒着搜索, 最后一个数一定不是Bad Prices,不断更新一个最小值,有比它大的就加一
#include <stdio.h>
#include <iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[150005];
while(n--){
int t;
cin>>t;
for(int i = 0; i < t; i ++){
cin >> a[i];
}
int Min = a[t-1];
int cnt = 0;
for(int i = t - 2; i >=0; i--){
if(a[i]>Min) cnt++;
else Min = a[i];
}
cout<<cnt<<endl;
}
return 0;
}