1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<vector> #include<cstdio> #include<ctime> #include<queue> using namespace std; inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; } const int maxn=50005; struct Tree { int leftyear,rightyear,max; bool known; Tree() {} Tree(int ly,int ry,int m,bool k):leftyear(ly),rightyear(ry),max(m),known(k) {} }; struct Segment_Tree { Tree tree[maxn*4]; #define ls index<<1 #define rs index<<1|1 void push_up(int index) { tree[index].leftyear=tree[ls].leftyear; tree[index].rightyear=tree[rs].rightyear; tree[index].max=max(tree[ls].max,tree[rs].max); tree[index].known=tree[ls].known&&tree[rs].known&&(tree[ls].rightyear+1==tree[rs].leftyear); } void build(int index,int Left,int Right,const int* a,const int* b) { if(Left==Right) { tree[index]=Tree(a[Left],a[Left],b[Left],1); return; } int mid=(Left+Right)>>1; build(ls,Left,mid,a,b); build(rs,mid+1,Right,a,b); push_up(index); } int query_max(int index,int Left,int Right) { if(Right<tree[index].leftyear||Left>tree[index].rightyear)return 0; if(Left<=tree[index].leftyear&&Right>=tree[index].rightyear)return tree[index].max; return max(query_max(ls,Left,Right),query_max(rs,Left,Right)); } bool query_known(int index,int Left,int Right) { if(Right<tree[index].leftyear||Left>tree[index].rightyear)return 1; if(Left<=tree[index].leftyear&&Right>=tree[index].rightyear)return tree[index].known; return query_known(ls,Left,Right)&&query_known(rs,Left,Right)&&(tree[ls].rightyear<Left||tree[rs].leftyear>Right||tree[ls].rightyear+1==tree[rs].leftyear); } } st; int n,m,a[maxn],b[maxn]; int main() { n=Get_Int(); for(int i=1; i<=n; i++)a[i]=Get_Int(),b[i]=Get_Int(); st.build(1,1,n,a,b); m=Get_Int(); for(int i=1; i<=m; i++) { int left=Get_Int(),right=Get_Int(); int l=st.query_max(1,left,left),r=st.query_max(1,right,right); if(right<=left)puts("false"); else if(!l&&!r)puts("maybe"); else { int tmp1=upper_bound(a+1,a+n+1,left)-a,tmp2=lower_bound(a+1,a+n+1,right)-a-1,l1,r1; if(tmp1>n)l1=0x7fffffff/2; else l1=a[tmp1]; if(tmp2<1)r1=-0x7fffffff/2; else r1=a[tmp2]; if(!l) { if(l1>r1||r1==-0x7fffffff/2) { puts("maybe"); continue; } int ans=st.query_max(1,l1,r1); if(ans>=r)puts("false"); else puts("maybe"); } else if(!r) { if(l1>r1||l1==0x7fffffff/2) { puts("maybe"); continue; } int ans=st.query_max(1,l1,r1); if(ans>=l)puts("false"); else puts("maybe"); } else { if(r>l) { puts("false"); continue; } if(l1>r1) { if(left+1==right)puts("true"); else puts("maybe"); continue; } int ans=st.query_max(1,l1,r1),known=st.query_known(1,l1,r1); if(ans>=r)puts("false"); else if(!known||left+1!=l1||right-1!=r1)puts("maybe"); else puts("true"); } } } return 0; }
|