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
| #include<iostream> #include<cstdio> #include<stack> #include<queue> #include<deque> #include<vector> #include<cstdlib> #include<string> #include<cstring> #include<algorithm> #include<ctime> #include<bitset> #include<set> #include<cmath> using namespace std;
#define rint register int #define Int64 long long #define max(x,y) (((x)>(y))?(x):(y)) #define min(x,y) (((x)<(y))?(x):(y)) #define clr(x,y) memset(x,y,sizeof(x)) #define sqar(x) (x)*(x) #define lowbit(x) (x&(-x)) #define swp(x,y) x^=y,y^=x,x^=y #define Maxn 50005 #define logn 20
void init(); inline int read();
int N,M; int val[Maxn]; int LG[Maxn]; int year[Maxn]; int ST[Maxn][logn];
int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif N=read(); for(int i=1;i<=N;i++){year[i]=read();val[i]=read();ST[i][0]=val[i];} init(); M=read(); while(M--){ int y=read(),x=read(); int posl=lower_bound(year+1,year+1+N,y)-year; int posr=lower_bound(year+1,year+1+N,x)-year; if((posl==N+1||y!=year[posl])&&(posr==N+1||x!=year[posr])){cout<<"maybe"<<endl;continue;} if((posl!=N+1&&y==year[posl])&&(posr==N+1||x!=year[posr])){ if(posl+1==posr){cout<<"maybe"<<endl;continue;} else{ int tmp=LG[(posr-1)-(posl+1)+1]; int maxv=max(ST[posl+1][tmp],ST[(posr-1)-(1<<tmp)+1][tmp]); if(maxv>=val[posl]){cout<<"false"<<endl;continue;} else {cout<<"maybe"<<endl;continue;} } } else if((posl==N+1||y!=year[posl])&&(posr!=N+1&&x==year[posr])){ if(posl==posr){cout<<"maybe"<<endl;continue;} else{ int tmp=LG[(posr-1)-posl+1]; int maxv=max(ST[posl][tmp],ST[(posr-1)-(1<<tmp)+1][tmp]); if(maxv>=val[posr]){cout<<"false"<<endl;continue;} else {cout<<"maybe"<<endl;continue;} } } else{ if(val[posl]<=val[posr]){cout<<"false"<<endl;continue;} else if(posl+1==posr){ if(x==y+1){cout<<"true"<<endl;continue;} else {cout<<"maybe"<<endl;continue;} } else{ int tmp=LG[(posr-1)-(posl+1)+1]; int maxv=max(ST[posl+1][tmp],ST[(posr-1)-(1<<tmp)+1][tmp]); if(maxv>=val[posr]){cout<<"false"<<endl;continue;} else if(posr-posl==x-y){ cout<<"true"<<endl; continue; } else {cout<<"maybe"<<endl;continue;} } } } return 0; }
inline int read(){ int x=0,sign=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')sign=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-48;c=getchar();} return x*sign; }
void init(){ LG[1]=0; for(int i=2;i<Maxn;i++){LG[i]=LG[i>>1]+1;} for(int i=1;i<logn;i++){ for(int j=1;j+(1<<i)-1<=N;j++){ ST[j][i]=max(ST[j][i-1],ST[j+(1<<i-1)][i-1]); } } }
|