# 洛谷 2471

### 因此，这道题只需要建立线段树保存区间最大值，区间是否有未知年份，区间的左右端是否有未知年份即可，只是讨论比较复杂.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

#define MX 500000
#define ls (node*2)
#define rs (node*2+1)
#define mid ((l+r)/2)

using namespace std;

map<int,int> mp;
typedef struct tnd{
int l,r;
int eptl,eptr,epta,mx;
}treend;
typedef struct yr{
int year,val;
}yrsl;
typedef struct qrs{
int mx,ept;
}qtype;
int n,q;
treend tree[MX];
yrsl src[MX];

void input()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%d",&src[i].year,&src[i].val),mp[src[i].year]=i;
scanf("%d",&q);
}

void build(int node,int l,int r)
{
tree[node].l=l,tree[node].r=r;
if(l==r)
{
tree[node].mx=src[l].val;
if(src[l].year!=src[l-1].year+1)tree[node].eptl=1;
if(src[r].year!=src[r+1].year-1)tree[node].eptr=1;
}
else
{
build(ls,l,mid),build(rs,mid+1,r);
tree[node].eptl=tree[ls].eptl,tree[node].eptr=tree[rs].eptr;
tree[node].epta=tree[ls].eptr||tree[ls].epta||tree[rs].epta;
tree[node].mx=max(tree[ls].mx,tree[rs].mx);
}
}

qtype query(int node,int ql,int qr)
{
int l=tree[node].l,r=tree[node].r;
int yl=src[l].year,yr=src[r].year;
qtype rt,r1,r2;
rt.ept=0,rt.mx=-2000000000;
if(ql<yl&&yr<qr)rt.ept=tree[node].epta||tree[node].eptl||tree[node].eptr,rt.mx=tree[node].mx;
else if(yr==ql)rt.ept=tree[node].eptr;
else if(yl==qr)rt.ept=tree[node].eptl;
else if(ql>=yr||qr<=yl);
else
{
r1=query(ls,ql,qr),r2=query(rs,ql,qr);
rt.ept=r1.ept||r2.ept,rt.mx=max(r1.mx,r2.mx);
}
return rt;
}

void work()
{
int a,b,lz,rz;
qtype rt;
for(int i=1;i<=q;i++){
scanf("%d%d",&a,&b);
if(a>b)cout<<"false\n";
else
{
rt=query(1,a,b);
lz=mp[a],rz=mp[b];
if(lz&&rz&&src[lz].val>=src[rz].val&&rt.mx<src[rz].val&&rt.ept==0)cout<<"true\n";
else if((lz==0&&rz==0)||
(lz>=1&&rz==0&&src[lz].val>rt.mx)||
(lz==0&&rz>=1&&rt.mx<src[rz].val)||
(lz>=1&&rz>=1&&rt.mx<src[rz].val&&src[lz].val>=src[rz].val&&rt.ept==1))cout<<"maybe\n";
else cout<<"false\n";
}
}
}

int main()
{
input(),build(1,1,n),work();
return 0;
}