题目
题意:
简而言之就是输出从最后开始遍历的递增到递减的符合这样条件的开头的下标(从右往左数)。
思路:
我们从最后开始遍历,然后先递增的遍历,然后再递减,最后结束的下标就是答案了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <cctype>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<ll> vecl;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
char c;
int sgn;
if (c = getchar(), c == EOF) return ;
while (c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1:1;
ret = (c == '-') ? 0:(c - '0');
while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return ;
}
int xxxxxxxxx = 1;
inline void outi(int x) {if (x > 9) outi(x / 10);putchar(x % 10 + '0');}
inline void outl(ll x) {if (x > 9) outl(x / 10);putchar(x % 10 + '0');}
inline void debug(ll x) {cout << xxxxxxxxx++ << " " << x << endl;}
inline void debugs(string s) {cout << s << endl;}
const int maxn = 2e5 + 10;
int a[maxn];
int main() {
int t; read(t); while (t--) {
int n; read(n); for (int i = 1; i <= n; i++) read(a[i]);
int k = n;
for (int i = n - 1; i >= 1; i--) {
if (a[i] >= a[i + 1]) k--;
else break;
}
for (int i = k - 1; i >= 1; i--) {
if (a[i] <= a[i + 1]) k--;
else break;
}
printf("%d\n", k - 1);
}
return 0;
}