P12827 [HackerEarth] bob and lines
普及
题目描述

Problem Statement:
Line segment intersection is one of the important part of mathematics. Bob will be given a set of n number of line segments, followed by set of q number of query lines. He is supposed to find how many line segments from set of n intersect given query line. As bob likes only parallel lines he will be given only lines parallel to x-axis or y-axis as a query line.Help bob to find the answer
Input formate:
First line is for the number of testcase t
First line of each testcase has two space separated integers n and q, denoting the number of given line segments and number of query lines respectively.
Next n lines contain four space separated integers X1,Y1,X2,Y2, denoting the end points of line segment
Next q lines contains 2 space inputs, either of the two types:
Type 1: 0 k --------------------> This denotes the line y=k
Type 2: k 0 --------------------> This denotes the line x=k
Constraints:
1 ≤ t ≤ 5
1 ≤ n ≤ 10^5
0 ≤ xi ≤ 10^5
0 ≤ yi ≤ 10^5
1 ≤ q ≤ 10^5
1 ≤ k ≤ 10^5

SAMPLE INPUT
1
4 3
2 3 2 5
2 2 4 3
3 2 5 2
4 1 4 3
2 0
0 2
3 0

SAMPLE OUTPUT
2
3
2

Explanation

Let co-ordinates (2,3) and (2,5) denote line segment 1, (2,2) (4,3) denote line segment 2, (3,2) and (5,2) denote line segment 3, (4,1) (4,3) denote line segment 4
For first query line (2,0),
Intersecting lines segments are 1 and 2, hence ans is 2
For second query line (0,2),
Intersecting lines segments are 2 , 3 and 4, hence ans is 3
For third query line (3,0),
Intersecting lines segments are 2 and 3, hence ans is 2

输入格式

见题面

输出格式

见题面

样例输入
2 2 83 996 874 4 193 611 166 630 317 683 0 0 415 0 819 0 771 346 0 100 0 0 32 0 281 411 0 0 837 807 0 0 795 2 0 0 751 77 0 0 37 512 0 0 377 0 168 0 903 0 673 428 0 0 463 631 0 259 0 642 0 326 0 0 706 278 0 0 920 951 0 0 842 116 0 0 666 0 228 739 0 0 976 135 0 0 626 984 0 0 676 0 333 686 0 0 288 932 0 0 603 0 243 364 0 544 0 0 551 0 637 0 885 0 803 86 0 0 320 993 0 592 0 524 0 0 615 786 0 982 0 0 999 0 99 0 539 272 0 146 0 875 0 620 0 110 0 0 769 0 354 626 0 0 361 0 246 628 0 0 379 0 952 0 449 0 802 0 124 0 478 631 0 0 196 64 52 150 293 130 393 455 780 455 135 802 152 673 622 157 117 474 164 951 514 592 76 392 505 830 719 983 241 642 111 262 554 213 694 421 486 241 368 616 510 371 281 416 833 237 452 371 276 401 982 12 383 896 925 811 40 366 200 855 994 937 94 228 493 803 130 978 910 99 653 493 501 485 282 75 395 336 762 144 852 8 193 441 507 722 19 65 488 209 851 905 68 234 285 379 439 247 896 128 841 253 140 945 46 336 199 194 2 253 193 177 584 682 198 671 748 561 518 324 49 720 831 475 121 733 426 23 884 449 629 47 43 955 520 740 309 483 196 206 165 716 214 513 864 469 623 701 102 481 977 148 830 935 453 651 49 806 967 13 365 202 529 823 552 270 890 475 552 901 582 720 894 640 441 164 791 33 102 557 20 417 224 688 997 58 600 289 13 434 215 105 345 509 223 718 915 354 798 515 992 480 925 611 347 286 560 432 215 25 783 117 667 347 694 468 988 671 113 156 508 854 36 754 806 663 987 514 318 213 946 414 654 39 395 388 623 9 604 863 550 197 463 988 540 366 375 497 508 579 87 100 864 913 491 263 901 416 690 890 0 0 952 0 696 0 576 660 0 718 0 574 0 505 0 568 0 0 41 514 0 0 300 377 0 0 873 0 963 0 139 279 0 617 0 205 0 0 17 424 0 0 394 0 805 583 0 0 653 510 0 259 0 799 0 0 693 238 0 742 0 711 0 0 217 0 451 190 0 26 0 0 233 0 235 0 341 0 349 160 0 496 0 550 0 267 0 21 0 0 24 0 573 0 509 0 301 878 0 24 0 595 0
样例输出
1 1 1 1 1 1 0 2 1 1 1 1 0 1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 2 1 0 1 1 1 1 1 1 2 1 1 2 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 2 1 1 1 2 1 2 2 1 0 1 1 0 1 1 2 12 8 28 28 30 26 29 33 29 6 31 25 33 16 8 22 26 27 20 2 28 28 23 28 29 32 25 19 30 25 20 27 23 31 19 6 23 23 25 25 19 32 29 25 4 4 28 31 25 12 5 29