"Problem description"
Little Q has a strong interest in computational geometry. He often stares at the plane Cartesian coordinate system and thinks
some interesting questions. Today, he thought of a very interesting topic:
first, the small Q will be selected on the x-axis positive half axis and the y-axis positive half axis respectively. A point. He then put the x-axis
Point One by one connected to the y-axis, forming?? Line segment and ensure that any two segments do not intersect. Small Q OK
This connection is available and has only one type. Finally, the small Q will give a M inquiry. For each query, you will
given a point P (Px, Py), how many points of intersection do the line OP and M segments produce?
Small Q found you are delving into the data structure, I hope you can help him solve the problem.
"input Format"
a 11th positive integer n, representing the number of segments;
The 2nd line contains n positive integers to indicate that small q is selected at the X axis and the 3rd line of the point is N positive integer, which indicates the ordinate of the point selected by the small q in the Y axis;
The 4th line contains a positive integer m, which indicates the number of queries;
then?? Rows, each row contains two positive integers px, Py, which represents the horizontal and vertical axis of the given point in the query.
"Output format"
total?? Line, each line contains a non-negative integer that represents the answer you gave to the query.
"Sample Input"
3
4 5 3
3 5 4
2
1 1
3 3
"Sample Output"
0
3
"Sample Interpretation"
then there's nothing in the tower.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <cctype>5#include <iostream>6#include <algorithm>7 using namespacestd;8 Const intBuf_size = -;9 CharBuf[buf_size], *buf_s = buf, *buf_t = buf +1;Ten Const intMAXN =200010; One Long LongX[MAXN], Y[MAXN]; A intN, M; - BOOLToLeft (intNumLong Long_x,Long Long_y) { - return(X[num] * _y + y[num] * (_x-x[num])) >=0; the } - intGETCNT (Long Long_x,Long Long_y) { - intL =0, R = n +1; - while(L < R-1) { + intMid = (L + r) >>1; - if(!mid) Break; + if(ToLeft (Mid, _x, _y)) L =mid; A ElseR =mid; at } - returnl; - } - intMain () { -Freopen ("hahaha.in","R", stdin); -Freopen ("Hahaha.out","W", stdout); inscanf"%d",&n); - for(inti =1; I <= N; ++i) toscanf"%d",&x[i]); + for(inti =1; I <= N; ++i) -scanf"%d",&y[i]); theSort (x +1, X + n +1); *Sort (y +1, Y + n +1); $scanf"%d",&m);Panax Notoginseng while(M--) { - int_x, _y; thescanf"%d%d",&_x,&_y); +printf"%d\n", getcnt (_x, _y)); A } the return 0; +}
Thinking: Math judgment + two-point answer
Test data See network Disk ~
Jinan study Day1 T3 pm