考试的时候线段树区间查询的return条件打成了l==r。。。。于是光荣爆20(线段树都不会打了?)
看膜博士的题解
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=1000000+10,inf=0x3f3f3f3f;
int n,m,p,lmtL[MAXN],lmtR[MAXN],L[MAXN],R[MAXN],key[MAXN],stack[MAXN],cnt;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch=' ')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!=' ')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
#define Mid ((l+r)>>1)
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,l,Mid
#define rson rs,Mid+1,r
struct Segment_Tree{
int Mx[MAXN<<2];
inline void PushUp(int rt)
{
Mx[rt]=max(Mx[ls],Mx[rs]);
}
inline void Build(int rt,int l,int r)
{
if(l==r)Mx[rt]=key[l];
else Build(lson),Build(rson),PushUp(rt);
}
inline int Mxquery(int rt,int l,int r,int k)
{
if(Mx[rt]<=k)return 0;
if(l==r)return l;
else
{
if(Mx[rs]>k)return Mxquery(rson,k);
else return Mxquery(lson,k);
}
}
inline int Psquery(int rt,int l,int r,int L,int R,int k)
{
if(L<=l&&r<=R)return Mxquery(rt,l,r,k);
int res=0;
if(R>Mid)res=Psquery(rson,L,R,k);
if(res)return res;
if(L<=Mid)res=Psquery(lson,L,R,k);
return res;
}
inline int Query(int L,int R,int k)
{
if(R<L)return L;
int res=Psquery(1,1,n,L,R,k);
return res?res+1:L;
}
};
Segment_Tree T;
#undef Mid
#undef ls
#undef rs
#undef lson
#undef rson
inline void init()
{
T.Build(1,1,n);
for(register int i=1;i<=n;++i)
if(key[i-1]&&key[i-1]<=i-1)lmtL[i]=i;
else lmtL[i]=lmtL[i-1];
for(register int i=n;i>=1;--i)
if(key[i]&&key[i]>i)lmtR[i]=i;
else lmtR[i]=lmtR[i+1];
for(register int i=n;i>=1;--i)
{
L[i]=R[i]=i;
L[i]=T.Query(lmtL[i],L[i]-1,R[i]);
stack[++cnt]=i;
while(cnt&&((L[i]<=key[stack[cnt]]&&key[stack[cnt]]<=R[i])||(!key[stack[cnt]])))
{
R[i]=stack[--cnt];
L[i]=T.Query(lmtL[i],L[i]-1,R[i]);
}
}
}
int main()
{
freopen("game.in","r",stdin);
freopen("game.out","w",stdout);
read(n);read(m);read(p);
for(register int i=1;i<=m;++i)
{
int x,y;
read(x);read(y);
key[x]=y;
}
key[0]=-inf,key[n]=inf;
init();
while(p--)
{
int s,t;
read(s);read(t);
if(L[s]<=t&&t<=R[s])puts("YES");
else puts("NO");
}
return 0;
}