分类讨论是比较好的,直接脑补容易炸。
本来以为是水题,后来发现是神题……
1 #include<bits/stdc++.h> 2 #define rep(a,b,c) for(int a=b;a<=c;a++) 3 using namespace std; 4 5 int a[5000005],b[5000005],n,m,t1,t2,t3,t4,li[1000005],q1[1000005],q2[1000005],lcnt,r1[1000005],r2[1000005],seq[1000005]; 6 7 void pushin(int p){ 8 li[++lcnt]=p; li[++lcnt]=p+1; li[++lcnt]=p-1; 9 } 10 11 void build(int p,int l,int r) { 12 if(l==r) a[p]=seq[l], b[p]=(seq[l]>1e+9?0:seq[l]); 13 else build(p*2,l,(l+r)/2), build(p*2+1,(l+r)/2+1,r), a[p]=max(a[p*2],a[p*2+1]), b[p]=max(b[p*2],b[p*2+1]); 14 } 15 16 int query(int p,int l,int r,int ql,int qr) { 17 if(l>qr||r<ql) return 0; 18 if(l>=ql&&r<=qr) return a[p]; 19 return max(query(p*2,l,(l+r)/2,ql,qr),query(p*2+1,(l+r)/2+1,r,ql,qr)); 20 } 21 22 int query2(int p,int l,int r,int ql,int qr) { 23 if(l>qr||r<ql) return 0; 24 if(l>=ql&&r<=qr) return b[p]; 25 return max(query2(p*2,l,(l+r)/2,ql,qr),query2(p*2+1,(l+r)/2+1,r,ql,qr)); 26 } 27 28 int main(){ 29 30 scanf("%d",&n); 31 rep(i,1,n) scanf("%d%d",&r1[i],&r2[i]), pushin(r1[i]); 32 33 scanf("%d",&m); 34 rep(i,1,m) scanf("%d%d",&q1[i],&q2[i]), pushin(q1[i]), pushin(q2[i]); 35 36 sort(li+1,li+lcnt+1); 37 lcnt=unique(li+1,li+lcnt+1)-li-1; 38 39 rep(i,1,n) r1[i]=lower_bound(li+1,li+lcnt+1,r1[i])-li; 40 rep(i,1,m) q1[i]=lower_bound(li+1,li+lcnt+1,q1[i])-li, q2[i]=lower_bound(li+1,li+lcnt+1,q2[i])-li; 41 42 rep(i,1,lcnt) seq[i]=2e+9; 43 rep(i,1,n) seq[r1[i]]=r2[i]; 44 45 build(1,1,lcnt); 46 47 rep(i,1,m) { 48 int tmp=query(1,1,lcnt,q1[i]+1,q2[i]-1),tmp2=query2(1,1,lcnt,q1[i]+1,q2[i]-1); 49 int I=seq[q1[i]],J=seq[q2[i]]; 50 if(I==2e+9 && J==2e+9) printf("maybe "); 51 else if(I==2e+9) if(tmp2>=J) printf("false "); else printf("maybe "); 52 else if(J==2e+9) if(tmp2>=I) printf("false "); else printf("maybe "); 53 else if(J>I || tmp2>=J) printf("false "); else if(tmp==2e+9) printf("maybe "); else printf("true "); 54 } 55 }