我还是太年轻了。。。
考场上就是直接枚举预处理当前位置左右延伸到的最远距离,好像是水了20。。
然后噶爷爷居然随机一下就AC了????mengbier
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<ctime> using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,L[1100000],R[1100000]; int p[1100000]; void extend(int i) { bool bk=true; while(bk==true) { bk=false; while(L[i]>1&&(p[L[i]-1]==0||(L[i]<=p[L[i]-1]&&p[L[i]-1]<=R[i]))) { bk=true, L[i]=min(L[i],L[L[i]-1]), R[i]=max(R[i],R[R[i]-1]); } while(R[i]<n&&(p[R[i]]==0||(L[i]<=p[R[i]]&&p[R[i]]<=R[i]))) { bk=true, L[i]=min(L[i],L[L[i]+1]), R[i]=max(R[i],R[R[i]+1]); } } } int rd[1100000]; int main() { freopen("game.in","r",stdin); freopen("game.out","w",stdout); srand(32647159); int m,Q,x,y; n=read(),m=read(),Q=read(); memset(p,0,sizeof(p)); for(int i=1;i<=m;i++)x=read(),p[x]=read(); for(int i=1;i<=n;i++)L[i]=R[i]=i; for(int i=1;i<=n;i++)rd[i]=i; random_shuffle(rd+1,rd+n+1); for(int i=1;i<=n;i++) extend(rd[i]); while(Q--) { x=read(),y=read(); if(L[x]<=y&&y<=R[x])printf("YES "); else printf("NO "); } return 0; }