/*
#include <stdio.h>
#define SIZE 80001
int stack[SIZE];
int top = -1;
void push(int data)
{
stack[++top] = data;
}
int pop()
{
if(top==-1) return 0;
return stack[top--];
}
int main()
{
int n;
long long int sum=0;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
int x;
scanf("%d", &x);
while(stack[top]<=x && top!=-1)
{
pop();
}
sum += top+1;
push(x);
}
printf("%lld", sum);
}
*/
#include <stdio.h>
#define SIZE 500001
struct tower
{
int num;
int h;
};
struct tower stack[SIZE];
int top=-1;
void push(struct tower data)
{
stack[++top]=data;
}
void pop()
{
stack[top--];
}
int main()
{
int n, sum=0;
struct tower tmp;
scanf("%d", &n);
for(int i=0; i<n; i++)
{
tmp.num = i+1;
scanf("%d", &tmp.h);
while (stack[top].h<=tmp.h && top!=-1)
{
pop();
}
if(top==-1) printf("0 ");
else printf("%d ", stack[top].num);
push(tmp);
}
}
탑 문제 다시한번 풀어보고 큰 수 뺄셈도 해보기