Insects

시간 제한5초메모리 제한512 MB

요약
흰 개미를 한 마리씩 추가할 때마다, x>=a이고 y>=b인 굶주린 흰 개미와 검은 개미 쌍이 생기지 않도록 먹여야 하는 최소 개미 수를 구한다.
난이도

어려움10점 중 8점

유형
정렬, 그리디, 이분 탐색, 세그먼트 트리
정답자
아직 제출이 없습니다

문제

You have nn black ants in your terrarium, and the ii-th black ant lives at coordinate (a_i,b_i)(a\_i, b\_i).

Each day for the next mm days, you will buy a new ant for your terrarium. You are only buying white ants, and the ii-th white ant that you are buying will live at coordinate (x_i,y_i)(x\_i, y\_i).

Each day, you feed some of your insects. If you feed an insect, the insect will not be hungry in that day. If the ii-th white ant is hungry and the jj-th black ant is hungry, and x_i≥a_jx\_i \geq a\_j and y_i≥b_jy\_i \geq b\_j, they will fight. Find, for each day, the smallest number of ants to feed such that there are no fights.

입력

The first line contains one integer nn (1≤n≤100,0001 \leq n \leq 100\\,000): the number of black ants in your terrarium.

Each of the next nn lines contains the description of black ants. The ii-th of them contain two integers, a_i,b_ia\_i, b\_i (0≤a_i,b_i≤100,0000 \leq a\_i, b\_i \leq 100\\,000).

The next line contains one integer mm (1≤m≤100,0001 \leq m \leq 100\\,000): the number of days in which you are going to buy new white ants.

Each of the next mm lines contains the description of white ants in the order you buy them, such that the ii-th of them contains two integers, x_i,y_ix\_i, y\_i (0≤x_i,y_i≤100,0000 \leq x\_i, y\_i \leq 100\\,000).

Note that different ants can live at points with the same coordinates.

출력

Print mm integers, such that the ii-th of them equals the smallest number of ants that you should feed to avoid fights among the black ants 1,2,…,n1,2,\ldots,n and the white ants 1,2,…,i1,2,\ldots,i.

예제1

  1. 예제 1

    입력
    3
    0 0
    1 1
    2 2
    4
    0 0
    1 1
    0 0
    3 3
    
    예상 출력
    1
    2
    2
    3