为什么我的(伪)单调栈过不了“丹钓战”???
  • 板块题目总版
  • 楼主HandWriting
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/7/22 23:49
  • 上次更新2023/10/27 18:50:16
查看原帖
为什么我的(伪)单调栈过不了“丹钓战”???
711338
HandWriting楼主2022/7/22 23:49
#include <bits/stdc++.h>
using namespace std;

int a[100001],b[100001],head[100001];
int sta[100001],top;

int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) cin>>b[i];
    sta[0]=n; ++top;
    for(int j=n-1;j>0;j--){
        while( a[j]!=a[sta[top-1]] &&
               b[j]> b[sta[top-1]] && top ){
            head[sta[--top]]=j;
        }
        sta[top++]=j;
    }
    for(int Q=0;Q<q;Q++){
        int l,r,ans=0;
        scanf("%d%d",&l,&r);
        for(int i=l;i<=r;i++){
            if(head[i]<l){
                ++ans;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

丹钓战 原题 只得了30pts呜呜呜,测试点8 9 10 TLE,后面全是SIGSEGV!

2022/7/22 23:49
加载中...