题目
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
const int maxn = 1e6 + 5, inf = 1e9 + 5, maxm = 1e6 + 5;
int a[maxn], b[maxn];
int n, m;
map<int, int> mp;
int suf[maxn], pre[maxn];
void solve()
{
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
int res = 0;
for(int i = 2; i <= n; i++){
if(a[i] <= a[i - 1]) res++;
}
int tmp = res;//因为最后肯定是左边负数右边正数,所有枚举分界线,取最小值
for(int i = 2; i <= n; i++){
if(a[i] <= a[i - 1]) tmp--;//tmp表示1~i-1区间的数乘负数,要多少次(不计乘负数的那次)
res = min(res, tmp + 1);
if(a[i] >= a[i - 1]) tmp++;//要加回来
}
cout << res << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
cin >> T;
while (T--)
{
solve();
}
return 0;
}