CF167D.Wizards and Roads

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In some country live wizards. They love to build cities and roads.

The country used to have kk cities, the jj -th city ( 1<=j<=k1<=j<=k ) was located at a point ( xjx_{j} , yjy_{j} ). It was decided to create another nkn-k cities. And the ii -th one ( k<i<=n ) was created at a point with coordinates ( xix_{i} , yiy_{i} ):

  • xi=(axi1+b) mod (109+9)x_{i}=(a·x_{i-1}+b) mod (10^{9}+9)
  • yi=(cyi1+d) mod (109+9)y_{i}=(c·y_{i-1}+d) mod (10^{9}+9)

Here aa , bb , cc , dd are primes. Also, ac,bda≠c,b≠d .

After the construction of all nn cities, the wizards have noticed something surprising. It turned out that for every two different cities ii and jj , xixjx_{i}≠x_{j} and yiyjy_{i}≠y_{j} holds.

The cities are built, it's time to build roads! It was decided to use the most difficult (and, of course, the most powerful) spell for the construction of roads. Using this spell creates a road between the towns of uu , vv ( yuy_{u} > yvy_{v} ) if and only if for any city ww which lies strictly inside the corner at the point uu , vv (see below), there is a city ss that does not lie in the corner, which is located along the xx -coordinate strictly between ww and uu and simultaneously y_{s}>y_{v} .

A corner on the points p2p_{2} ( x2x_{2} , y2y_{2} ), p1p_{1} ( x1x_{1} , y1y_{1} ) ( y_{1}<y_{2} ) is the set of points ( x,yx,y ), for which at least one of the two conditions is fulfilled:

  • min(x1,x2)<=x<=max(x1,x2)min(x_{1},x_{2})<=x<=max(x_{1},x_{2}) and y>=y1y>=y_{1}
  • y1<=y<=y2y_{1}<=y<=y_{2} and (xx2)(x1x2)>=0(x-x_{2})·(x_{1}-x_{2})>=0

The pictures showing two different corners In order to test the spell, the wizards will apply it to all the cities that lie on the xx -coordinate in the interval [L,R][L,R] . After the construction of roads the national government wants to choose the maximum number of pairs of cities connected by the road, so that no city occurs in two or more pairs. Your task is for each mm offered variants of values LL , RR to calculate the maximum number of such pairs after the construction of the roads. Please note that the cities that do not lie in the interval [L,R][L,R] on the xx -coordinate, do not affect the construction of roads in any way.

输入格式

The first line contains two space-separated integers nn , kk ( 1<=k<=n<=1051<=k<=n<=10^{5} , k<=30k<=30 ). Next kk lines contain coordinates of the cities' location points from the first to the kk -th one. The jj -th line contains space-separated pair of integers xjx_{j} , yjy_{j} ( 0<=x_{j},y_{j}<10^{9}+9 ) — coordinates of the jj -th city.

The next line contains space-separated integers a,b,c,da,b,c,d ( 2<=a,b,c,d<10^{9}+9 ). It is guaranteed that those numbers are prime and also that ac,bda≠c,b≠d .

It's guaranteed, that for every two different cities ii and jj , xixjx_{i}≠x_{j} and yiyjy_{i}≠y_{j} holds.

The next line contains integer mm ( 1<=m<=1051<=m<=10^{5} ) — the number of variants to build the roads. Next mm lines contain pairs of space-separated integers LiL_{i} , RiR_{i} ( 0<=L_{i}<=R_{i}<10^{9}+9 ) — the variants of choosing the cities to build the roads.

输出格式

For any pair of numbers LiL_{i} , RiR_{i} print the answer to the problem on a single line. Print the answers for the pairs in the order, in which the pairs are given in the input data.

输入输出样例

  • 输入#1

    6 6
    0 0
    1 1
    2 2
    3 3
    4 4
    5 5
    2 3 3 2
    4
    0 5
    1 4
    2 3
    3 3
    

    输出#1

    3
    2
    1
    0
    
  • 输入#2

    6 1
    0 0
    3 5 23917 11
    4
    0 1000000008
    0 10
    100 150
    200 10000
    

    输出#2

    2
    1
    0
    1
    

说明/提示

In the first sample the roads connect the cities in a chain in the order of increasing of xx .

In the second sample the remaining 5 cities will be located at points (5, 11); (20, 263098); (65, 292514823); (200, 76958738); (605, 622120197)(5, 11); (20, 263098); (65, 292514823); (200, 76958738); (605, 622120197) .

首页