#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++)cin >> a[i];
int cute;
cin >> cute;
int ans = 0;
int l = 1, r = n + 1;
for (int i = n; i >= l; i--) if (a[i] > cute)l++, r = i, ans++;
ans += r - l + 1;
cout << ans;
}
双指针模拟
已知交换一定不劣,于是能交换就交换,用l记录队伍头部的位置,用r记录小猫的位置。所有能交换的都交换完之后剩下的步数就是r-l+1

京公网安备 11010502036488号