http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=6006
题意:每次取一个数放到最前,使得数组不递减的最少次数;
思路:b数组排好序就是a的最终结果,从n-1到0开始遍历,如果位置的数不同就是要把a的这个数进行move,下一个数a还要是加上ans偏移与b匹配。因为可以任意取,所以每个取的都可以按顺序了,最大也就是n;
#include<algorithm>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-16
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back`
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=2e5+9;
const int mod=998244353;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
int a[maxn],b[maxn];
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
b[i]=a[i];
}
int ans=0;
sort(b,b+n);
for(int i=n-1;i>=0;i--)
{
if(a[i]!=b[i+ans]) ans++;
}
cout<<ans<<endl;
}
return 0;
}