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.

33 lines
628 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int stk[N], tt;
/**
测试用例:右边第一个比我大
6
6 10 3 7 4 12
结果:
10 12 7 12 12 -1
*/
int a[N], res[N];
int main() {
freopen("830_RightBigger.in", "r", stdin);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = n; i; i--) {
while (tt && a[i] >= stk[tt]) tt--;
if (tt == 0)
res[i] = -1;
else
res[i] = stk[tt];
stk[++tt] = a[i];
}
for (int i = 1; i <= n; i++) cout << res[i] << " ";
return 0;
}