代码
linda0471
·
·
个人记录
//央视奶牛
#include<bits/stdc++.h>
using namespace std;
const int N = 3e6 + 5;
int n, a[N], stk[N], ans[N], tt = -1;
void push(int x) {
stk[++tt] = x;
}
void pop() {
tt--;
}
bool empty() {
return tt == -1;
}
int size() {
return tt + 1;
}
int top() {
return stk[tt];
}
int main() {
cin >> n ;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = n; i >= 1; i--) {
while(tt >= 0 && a[top()] <= a[i]) pop();
ans[i] = top();
push(i);
}
for(int i = 1; i <= n; i++) cout << ans[i] << endl;
return 0;
}