//线段树维护区间最大值,区间查找时使用二分,分别找到第一个大于等于区间左右两端的年份,通过相等关系具体分析
//m*log(n)
#include<bits/stdc++.h>
using namespace std;
const int MAX=5e4+10;
int Y[MAX],R[MAX];
struct node{
int l,r,maxn;
}tr[MAX*4];
void build(int now,int l,int r){
tr[now].l=l,tr[now].r=r;
if(l==r){
tr[now].maxn=R[l];
return;
}
int mid=l+r>>1;
build(now<<1,l,mid);
build(now<<1|1,mid+1,r);
tr[now].maxn=max(tr[now<<1].maxn,tr[now<<1|1].maxn);
return;
}
int query(int now,int l,int r){
if(l>r) return 0;
if(tr[now].l>r||tr[now].r<l) return 0;
if(tr[now].l>=l&&tr[now].r<=r){
return tr[now].maxn;
}
return max(query(now<<1,l,r),query(now<<1|1,l,r));
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d%d",&Y[i],&R[i]);
}
build(1,1,n);
int m;
scanf("%d",&m);
while(m--){
int ly,ry;
scanf("%d%d",&ly,&ry);
int l=lower_bound(Y+1,Y+n+1,ly)-Y,r=lower_bound(Y+1,Y+n+1,ry)-Y;//二分查找
if(Y[l]==ly&&Y[r]==ry){//两端均存在,只有这种情况可能会输出true
int Maxn=query(1,l+1,r-1);//注意查询范围
if(R[l]<R[r]||Maxn>=R[r]){//右端点值超过左端点,或中间值不严格小于右端点
printf("false\n");
}
else if(ry-ly>r-l){//如果中间有不存在年份输出maybe
printf("maybe\n");
}
else{
printf("true\n");
}
}
else if(Y[l]==ly){
int Maxn=query(1,l+1,r-1);//
if(Maxn>=R[l]){//注意判断条件
printf("false\n");
}
else{
printf("maybe\n");
}
}
else if(Y[r]==ry){
int Maxn=query(1,l,r-1);//左端点虚则可以扩大左侧查找范围
if(Maxn>=R[r]){
printf("false\n");
}
else{
printf("maybe\n");
}
}
else{
printf("maybe\n");//两边均不存在则无法判断
}
}
return 0;
}
04-26
1190

08-26
6586

02-14
327

08-01
218

07-28