题目
视频讲解
代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], n, s[N], t; // s[1 2 3 ...]
int main() {
cin >> n;
s[0] = -1;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
while (t && a[s[t]] >= a[i]) --t;
s[++t] = i;
cout << s[t - 1] << " ";
}
return 0;
}
欢迎分享,引用。若转载,请联系我,谢谢配合。 本文地址:https://qoogle.top/xiaoxu-tutorial-bas-the-first-small-value-from-the-left/
1posting
[…] [应用] 左侧第一个小的值 […]