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
| #include <bits/stdc++.h> #include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <stdlib.h>
using namespace std; #define LL long long #define ll long long #define ULL unsigned long long #define ls rt<<1 #define rs rt<<1|1 #define one first #define two second #define MS 50009 #define INF 1e18 #define mod 99999997 #define Pi acos(-1.0) #define Pair pair<LL,LL> #define eps 1e-9
LL n,m,k; LL p[MS][31]; LL ha[MS]; LL lg2[MS]; map<LL,LL> mp;
void init_lg2(){ lg2[1] = 0; for(int i=2;i<=n;i++) lg2[i] = lg2[i/2]+1; }
void init_st(){ for(int i=1;i<=lg2[n];i++){ for(int j=1;j+(1<<(i-1))<=n;j++){ p[j][i] = max(p[j][i-1],p[j+(1<<(i-1))][i-1]); } } }
LL get_max(LL l,LL r){ LL t = lg2[r-l+1]; return max(p[l][t],p[r-(1<<t)+1][t]); }
int main(){ ios::sync_with_stdio(false); cin >> n; init_lg2(); for(int i=1;i<=n;i++){ cin >> ha[i] >> p[i][0]; mp[ha[i]] = 1; } init_st(); cin >> m; while(m--){ LL x,y; cin >> x >> y; LL l = lower_bound(ha+1,ha+n+1,x) - ha; LL r = lower_bound(ha+1,ha+n+1,y) - ha; LL cl = get_max(l,l); LL cr = get_max(r,r); if(l > r) cout << "false\n"; else if(!mp[x] && !mp[y]){ cout << "maybe\n"; } else if(mp[x] && !mp[y]){ LL t = get_max(l+1,r-1); if(t >= cl && r-1>=l+1) cout << "false\n"; else cout << "maybe\n"; } else if(!mp[x] && mp[y]){ LL t = get_max(l,r-1); if(t >= cr && r-1>=l) cout << "false\n"; else cout << "maybe\n"; } else if(mp[x] && mp[y]){ if(cr > cl) cout << "false\n"; else{ if(y-x == r-l){ if(r == l+1) cout << "true\n"; else{ LL t = get_max(l+1,r-1); if(t >= cr) cout << "false\n"; else cout << "true\n"; } } else{ if(r == l+1) cout << "maybe\n"; else{ LL t = get_max(l+1,r-1); if(t >= cr) cout << "false\n"; else cout << "maybe\n"; } } } } else{ printf("----\n"); } }
return 0; }
|