You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
483 B
28 lines
483 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
int n;
|
|
const int N = 1e5 + 10;
|
|
int a[N];
|
|
int stk[N], tt;
|
|
int res[N];
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 1; i <= n; i++)cin >> a[i];
|
|
for (int i = n; i >= 1; i--) {
|
|
while (tt && a[stk[tt]] > a[i]) {
|
|
res[stk[tt]]=i;
|
|
tt--;
|
|
}
|
|
stk[++tt]=i;
|
|
}
|
|
for (int i = 1; i <= n; i++)
|
|
res[i]?printf("%d ",a[res[i]]):printf("-1 ");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|