#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
#include <cstdlib>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 2000010;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
int n;
int h[MAXN];
int st[MAXN];
int f[MAXN];
int top;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
}
for (int i = n; i >= 1; i--) {
while (top != 0 && h[st[top]] <= h[i]) {
top--;
}
f[i] = top ? st[top] : 0;
st[++top] = i;
}
for (int i = 1; i <= n; i++) {
printf("%d\n", f[i]);
}
return 0;
}
P2947 [USACO09MAR]Look Up S(单调栈)
最新推荐文章于 2024-03-26 08:41:30 发布