제출 #920967

#제출 시각아이디문제언어결과실행 시간메모리
920967kxdTrampoline (info1cup20_trampoline)C++17
100 / 100
1084 ms77712 KiB
#include <bits/stdc++.h>
//#define DEBUG 1106
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define p_q priority_queue
#define m_p make_pair
#define pii pair<int,int>
#define endl '\n'
#define INIT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define forn(i,n) for (int i = 0; i < n; i++)
#define forn1(i,n) for (int i = 1; i <= n; i++)
#define all(x) x.begin(),x.end()
#define ft first
#define sd second
#define lowbit(x) (x&(-x))
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl;
#else
#define debug(x) 1106;
#endif

using namespace std;
const int N = 2e5+5;
const int M = 25;
const int inf = 1e9;
const int INF = 1e18;
const int MOD = 1e9+7;

int twok[N][M];
int row[N], col[N];

map<int,vector<int>> mp;
map<pii,int> id;

signed main() {
	INIT
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif
	///////////
    int r, c, n;
	cin >> r >> c >> n;
    forn1(i,n) {
        cin >> row[i] >> col[i];
        id[m_p(row[i],col[i])] = i;
        mp[row[i]].pb(col[i]);
    }
    for(auto x: mp) {
        sort(all(mp[x.ft]));
    }
    forn1(i,n) {
        auto it = lower_bound(all(mp[row[i]+1]), col[i]);
        if (it == mp[row[i]+1].end()) continue;
        twok[i][0] = id[m_p(row[i]+1,*it)];
    }
    forn1(j,M-1) {
        forn1(i,n) {
            twok[i][j] = twok[twok[i][j-1]][j-1];
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(x1>x2 || y1>y2) {
        	cout << "No" << endl;
        	continue;
		}
        if(x1==x2) {
        	cout << "Yes" << endl;
        	continue;
		}
        auto it = lower_bound(all(mp[x1]),y1);
        int u;
        if (it == mp[x1].end()) u = 0;
        else u = id[m_p(x1,*it)];
        int dist = x2-x1-1;
        forn(i,M) {
            if(dist&(1<<i)) {
                u = twok[u][i];
            }
        }
        if(u==0 || col[u]>y2) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...