简直丧心病狂,调了整整一天,感觉整个人都不好了,应该是边界处理出问题了吧,到最后好像还是wa了一个点,真的不想写这道破题了= =,各种情况的特判,不停wa,后来发现可以是负数,自己的读入优化打错了,简直醉,线段树很好写,但是各种情况真的太难判了,hzwer说得好,这种题一遍就过真是神。
附我不知道到底哪里错了的90分代码
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define max(a,b) (a>b?a:b)
using namespace std;
const int N=50010;
int n,m,qr,chua,chub,ans,ql,a[N],rn[N],qknow;
struct data{
int know,x;
}tr[40*N];
inline int geti()
{
register int a=0,b=0;register char ch;
while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');ch=='-'?b=1:a=ch-'0';
while(ch=getchar(),ch>='0'&&ch<='9')a=(a<<3)+(a<<1)+ch-'0';return b?-a:a;
}
void build(int x,int l,int r)
{
if (l==r){tr[x].know=1;tr[x].x=rn[l];return;}
int mid=(l+r)>>1;
int x1=x<<1,x2=x<<1|1;
build(x1,l,mid);build(x2,mid+1,r);
tr[x].x=max(tr[x1].x,tr[x2].x);
if (tr[x1].know==0||tr[x2].know==0||a[mid]+1!=a[mid+1])tr[x].know=0;
else tr[x].know=1;
}
void query(int x,int l,int r)
{
if (chua<=l&&chub>=r)
{
ans=max(ans,tr[x].x);
if (qknow!=0)qknow=tr[x].know;
return;
}
if (l==r){qknow=0;return;}
//cout<<x<<' '<<l<<' '<<r<<endl;
int mid=(l+r)>>1;
if (chua<=mid)query(x<<1,l,mid);
if (chub>mid)query(x<<1|1,mid+1,r);
}
int findy(int x)
{
int l=1,r=n,mid;
if(x>a[n])return r+1;
while(l!=r)
{
mid=(l+r)>>1;
if (a[mid]<x)l=mid+1;
else r=mid;
// cout<<l;
}
return l;
}
int main()
{
// freopen("std.in","r",stdin);
// freopen("std.out","w",stdout);
n=geti();
for (int i=1;i<=n;i++)
a[i]=geti(),rn[i]=geti();
m=geti();
int k=m;
build(1,1,n);
// for (int i=1;i<=15;i++)
// cout<<tr[i].x<<' '<<tr[i].know<<endl;
while(m--)
{
bool flagl=0,flagr=0;
ql=geti();qr=geti();
if (ql>a[n]||qr<a[1]){cout<<"maybe"<<endl;continue;}
if (ql==qr||qr<ql){cout<<"false"<<endl;continue;}
int x=findy(ql),y=findy(qr);
chua=x,chub=y;
if (a[x]!=ql)flagl=1;else chua++;if (a[y]!=qr)flagr=1;chub--;
if (ql+1==qr){if (flagl||flagr)cout<<"maybe"<<endl;else if(rn[x]>=rn[y])cout<<"true"<<endl;else cout<<"false"<<endl;continue;}
ql++;qr--;ans=0;qknow=-1;query(1,1,n);
if (a[x]+1!=a[chua]||a[chub]+1!=a[y])qknow=0;
// if (k-m==2850)cout<<qknow;
if(!flagl&&!flagr)
{
if (rn[x]>=rn[y]&&rn[y]>ans&&qknow)cout<<"true"<<endl;
else if (rn[x]>=rn[y]&&rn[y]>ans&&!qknow)cout<<"maybe"<<endl;
else cout<<"false"<<endl;
}
else if (!flagl&&flagr)
{
if(rn[x]>ans)cout<<"maybe"<<endl;
else cout<<"false"<<endl;
}
else if (flagl&&!flagr)
{
// cout<<ans<<' ';
if(rn[y]>ans)cout<<"maybe"<<endl;
else cout<<"false"<<endl;
}
else cout<<"maybe"<<endl;
}
return 0;
}