#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!