new file: P5788.cpp

This commit is contained in:
hanyixuanten committed 2026-10-28 10:59:36 +00:00
1 parent c622586277
commit 06fa6530a0
2 files changed
+71

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
#include<bits/stdc++.h>
using namespace std;
int n;
int a[3000005];
int stk[3000005];
int top = 0;
int ans[3000005];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for(int i = n; i >= 1; --i) {
while(top > 0 && a[stk[top]] <= a[i]) top--;
stk[++top] = i;
ans[i] = stk[top - 1];
}
for(int i = 1; i <= n; ++i) printf("%d ", ans[i]);
}