structST { /* ======================================== */ int st[maxn][maxlg], lg2[maxn]; voidinit_lg( int N ){ lg2[1] = 0; for( int i = 2; i <= N; ++ i ) lg2[i] = lg2[i >> 1] + 1; } voidinit( int N, int val[] ){ init_lg( N ); for( int i = 1; i <= N; ++ i ) st[i][0] = val[i]; for( int j = 1; ( 1 << j ) <= N; ++ j ) { for( int i = 1; i + ( 1 << j ) - 1 <= N; ++ i ) { st[i][j] = max( st[i][j - 1], st[i + ( 1 << ( j - 1 ) )][j - 1] ); } } } intquery( int l, int r ){ int k = lg2[r - l + 1]; returnmax( st[l][k], st[r - ( 1 << k ) + 1][k] ); } /* ======================================== */ } st;
map<int, int> mp; int a[maxn]; int ys[maxn], rs[maxn];
voidsolve( ){ int n = read( );
for( int i = 1; i <= n; ++ i ) { ys[i] = read( ); rs[i] = read( ); } st.init( n, rs );
int q = read( ); for( int i = 1; i <= q; ++ i ) { int Y = read( ), X = read( ); int py = lower_bound( ys + 1, ys + n + 1, Y ) - ys; int px = lower_bound( ys + 1, ys + n + 1, X ) - ys;
int l = upper_bound( ys + 1, ys + n + 1, Y ) - ys; int r = lower_bound( ys + 1, ys + n + 1, X ) - ys - 1;
int mx = 0; if( l <= r ) mx = st.query( l, r );
bool hasY = 0, hasX = 0; if( py <= n && ys[py] == Y ) hasY = 1; if( px <= n && ys[px] == X ) hasX = 1;