AcWing 3437. 打印极值点下标
原题链接
简单
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int N = 1e6+10;
int t,n,m,k,l,r,op,x,y;
int f[N];
void solve(){
cin>>n;
for(int i = 1;i<=n;i++){
cin>>f[i];
}
if(f[1]!=f[2])cout<<0<<" ";
for(int i = 2;i<=n-1;i++){
if((f[i]>f[i-1]&&f[i]>f[i+1])||
(f[i]<f[i-1]&&f[i]<f[i+1])){
cout<<i-1<<" ";
}
}
if(f[n-1]!=f[n])cout<<n-1<<" ";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}