Untitled
unknown
plain_text
2 years ago
792 B
7
Indexable
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
const double PI = 3.14159265358979;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ll nax = 1000005;
const int LOG = 25;
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int left = 0, right = n - 1, ans = 0;
while(left <= right) {
int mid = (left + right ) / 2;
if (a[mid] <= a[n - 1]) {
ans = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t; cin >> t; while(t--)
solve();
return 0;
}
Editor is loading...
Leave a Comment