Cats and Rats

All submissions for this problem are available.
###Read problems statements in [Vietnamese](http://www.codechef.com/download/translated/COOK104/vietnamese/CATSRATS.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/COOK104/mandarin/CATSRATS.pdf) and [Bengali](http://www.codechef.com/download/translated/COOK104/bengali/CATSRATS.pdf) as well. There are $N$ cats (numbered $1$ through $N$) and $M$ rats (numbered $1$ through $M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats can only move with constant speed $1$. For each valid $i$, the $i$th cat is initially sleeping at a point $a_i$. At a time $s_i$, this cat wakes up and starts moving to a final point $b_i$ with constant velocity and without any detours (so it arrives at this point at the time $e_i = s_i + a_ib_i$). After it arrives at the point $b_i$, it falls asleep again. For each valid $i$, the $i$th rat is initially hiding at a point $c_i$. At a time $r_i$, this rat stops hiding and starts moving to a final point $d_i$ in the same way as the cats ― with constant velocity and without any detours, arriving at the time $q_i = r_i + c_id_i$ (if it does not get eaten). After it arrives at the point $d_i$, it hides again. If a cat and a rat meet each other (they are located at the same point at the same time), the cat eats the rat, the rat disappears and cannot be eaten by any other cat. A sleeping cat cannot eat a rat and a hidden rat cannot be eaten ― formally, cat $i$ can eat rat $j$ only if they meet at a time $t$ satisfying $s_i \le t \le e_i$ and $r_j \le t \le q_j$. Your task is to find out which rats get eaten by which cats. It is guaranteed that no two cats will meet a rat at the same time. ### Input  The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.  The first line of each test case contains two spaceseparated integers $N$ and $M$.  $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$th of these lines contains three spaceseparated integers $a_i$, $b_i$ and $s_i$.  $M$ more lines follow. For each $i$ ($1 \le i \le M$), the $i$th of these lines contains three spaceseparated integers $c_i$, $d_i$ and $r_i$. ### Output For each test case, print $M$ lines. For each valid $i$, the $i$th of these lines should contain a single integer ― the number of the cat that will eat the $i$th rat, or $1$ if no cat will eat this rat. ### Constraints  $1 \le T \le 10$  $0 \le N \le 1,000$  $1 \le M \le 1,000$  $1 \le a_i, b_i, s_i \le 10^9$ for each valid $i$  $1 \le c_i, d_i, r_i \le 10^9$ for each valid $i$  all initial and final positions of all cats and rats are pairwise distinct ### Example Input ``` 2 8 7 2 5 1 1 4 1 9 14 10 20 7 9 102 99 1 199 202 1 302 299 3 399 402 3 6 3 1 10 15 10 100 101 1 201 200 1 300 301 5 401 400 5 1000 1010 1020 8 8 2 8 2 12 18 2 22 28 4 32 38 4 48 42 2 58 52 3 68 62 1 78 72 3 3 6 3 13 19 3 21 25 3 31 39 3 46 43 4 59 53 2 65 61 4 79 71 2 ``` ### Example Output ``` 1 4 5 6 7 8 1 1 2 3 4 5 6 7 8 ```Author:  erfaniaa 
Editorial  https://discuss.codechef.com/problems/CATSRATS 
Tags  cook104, easy, erfaniaa 
Date Added:  16032019 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 