Đăng nhập để hỏi chi tiết


Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,a[100005];
cin >> n;
for (int i=0;i<n;i++) cin >> a[i];
stack<int> s;
for (int i=0;i<n;i++) {
while (!s.empty() && a[s.top()] >= a[i]) s.pop();
if (s.empty()) cout << 0 << " ";
else cout << s.top() + 1 << " ";
s.push(i);
}
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin