MRECT1 - Điểm trên cạnh hình chữ nhật - HRASTOVI

Tác giả: RR

Ngôn ngữ: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
#define MAXN 300111
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define MP make_pair
#define UB upper_bound
#define LB lower_bound
#define oo 1000111000
using namespace std;

int n,m;
pair<int,int> a[MAXN],b[MAXN];

int main() {
    scanf("%d",&n);
    FOR(i,1,n) {
        int x,y;
        scanf("%d %d",&x,&y);
        a[i]=MP(x,y);
        b[i]=MP(y,x);
    }
    n++;
    a[n]=MP(oo,oo);
    b[n]=MP(oo,oo);
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    scanf("%d",&m);
    FOR(i,1,m) {
        int x1,y1,x2,y2;
        scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
        int res=UB(a+1,a+n+1,MP(x1,y2))-LB(a+1,a+n+1,MP(x1,y1))
               +UB(a+1,a+n+1,MP(x2,y2))-LB(a+1,a+n+1,MP(x2,y1))
               +UB(b+1,b+n+1,MP(y1,x2-1))-LB(b+1,b+n+1,MP(y1,x1+1))
               +UB(b+1,b+n+1,MP(y2,x2-1))-LB(b+1,b+n+1,MP(y2,x1+1));
        printf("%d\n",res);
    }
    return 0;
}

Download