1 条题解

  • 0
    @ 2025-10-8 17:01:46
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e5+10;
    int a[N],p[N];
    stack<int>stk;
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    	for(int i=n;i>=1;i--)
    	{
    		while( !stk.empty() && a[i]>=a[stk.top()] ) stk.pop();
    		p[i]=stk.empty() ? 0 : stk.top();
    		stk.push(i);
    	}
        for(int i=1;i<=n;i++)printf("%d\n",p[i]);
        return 0;
    }
    
    • 1

    *【栈:单调栈】向右看齐[USACO09MAR] Look Up S

    信息

    ID
    2628
    时间
    500ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    269
    已通过
    63
    上传者