比赛 26暑假集训模拟赛2 评测结果 AAATTTTTTTTTTTTTTTTT
题目名称 丹钓战 最终得分 15
用户昵称 董彰奇 运行时间 18.732 s
代码语言 C++ 内存使用 5.78 MiB
提交时间 2026-07-02 11:04:09
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n, q, a[500010], b[500010];
struct node
{
    int a; int b;
};
stack<node>st;
int main()
{
    freopen("stack.in","r",stdin);
    freopen("stack.out","w",stdout);
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &b[i]);
    }
    for(int i = 1; i <= q; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        int cnt = 0;
        for(int j = l; j <= r; j++)
        {
            while(!st.empty() && !(st.top().a != a[j] &&  b[j] < st.top().b))
            {
                st.pop();
            }
            if(st.empty())
            {
                cnt++;
            }
            st.push({a[j], b[j]});
        }
        while(st.size())st.pop();
        printf("%d\n", cnt);
    }
    return 0;
}