#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9;
int s[N], top;
int a[N], ans[N];
int main()
{
int n;
scanf_s("%d", &n);
for (int i = 1; i <= n + 1; ++i)
scanf_s("%d", a + i);
a[0] = inf;
a[n + 1] = inf;
for (int i = 1; i <= n + 1; ++i)
if (a[i] < a[s[top]])
s[++top] = i;
else
{
while (a[i] > a[s[top]])
{
ans[s[top]] = i - s[top] - 1;
top--;
}
s[++top] = i;
}
for (int i = 1; i <= n; ++i)
printf("%d", ans[i]);
puts("");
}
单调栈入门题(站队问题)
最新推荐文章于 2024-10-28 14:12:21 发布