比赛 26暑假集训模拟赛2 评测结果 AAATTTWWWWWWWWWWWWWW
题目名称 丹钓战 最终得分 15
用户昵称 梦那边的美好CE 运行时间 5.391 s
代码语言 C++ 内存使用 7.49 MiB
提交时间 2026-07-02 11:47:37
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fo(iii,aaa,bbb) for(int iii=aaa;iii<=bbb;iii++)
#define foa(ppp,aaa) for(auto ppp:aaa)
#define pb push_back
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((l+r)>>1)
#define N (514514)
#define debug puts("HERE!")
using namespace std;

struct node{
    int a;int b;
}s[N];
int n,q;

void solve1(int l,int r){
    stack<node>st;int ans=0;
    fo(i,l,r){
        if(st.empty()){
            st.push(s[i]);
        }else{
            while(1){
                if(st.empty()){
                    st.push(s[i]);break;
                }
                if((st.top().a!=s[i].a&&st.top().b>s[i].b)){
                    st.push(s[i]);
                    break;
                }else{
                    st.pop();
                }
            }
        }
        if(st.size()==1)ans++;
    }
    cout<<ans<<"\n";
    return;
}

signed main(){
    freopen("stack.in","r",stdin);freopen("stack.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);
    cin>>n>>q;
    fo(i,1,n)cin>>s[i].a;
    fo(i,1,n)cin>>s[i].b;
    while(q--){
        int l,r;
        cin>>l>>r;
        if(n<=10000){
            solve1(l,r);
        }
    }
    return 0;
}