Medium Search Techniques > Binary Search/Bisection

**N** cars are lying in some points in a road.If a car is currently in **P** point after **1** second the car moves to **P+1** point. Now for each query you have to count how many cars are current in the given two points after the given time. Input: ------ Input start with the number of Testcases. Each testcase starts with **N** and **Q** where **N** denotes number of cars at present in the road and **Q** denotes number of query. next line contains the n integers which denotes the initial positions of **N** cars. next **Q** lines contain 3 integers **X,Y,T** and you have to count the number of cars are present in between **x** and **y** point (inclusive) after **T** second(s). Output: ------- for each testcase you have to print the case number. For each query you have to print the number of cars are present in between the given two points after the given time. See sample testcases for further details. Constraints: ------- **Testcase <= 10** **N <= 50000** **Q <= 10000** **1 <= initial position <= 10^9** **1 <= X,Y <= 10^9** **1 <= T <= 10^9** Sample Input ------------ 1 5 3 100 800 400 500 10000 1 500 3 200 400 5 100 1000 1 Sample Output ------------- Case 1: 2 0 4

Shagor Hasan

Language |
Time Limit (seconds) |

C | 2.00 |

C++ | 1.00 |

C++14 | 2.00 |

C# | 2.00 |

Go | 2.00 |

Java | 2.00 |

JavaScript | 2.00 |

Objective-C | 2.00 |

Perl | 2.00 |

PHP | 2.00 |

Python | 2.00 |

Python3 | 2.00 |

Ruby | 2.00 |

VB.Net | 2.00 |

Solve/Submission

# | User | Language | Timing |
---|---|---|---|

01 | Morass | Cpp14 | 0.06s |

02 | feodorv | C | 0.09s |

03 | joker70 | Cpp14 | 0.09s |

04 | dmehrab06 | Cpp14 | 0.10s |

05 | Mahmudul_Tushar | Cpp | 0.10s |

06 | as_couple | Cpp14 | 0.10s |

07 | MamunAmin | Cpp14 | 0.10s |

08 | Ishrak | Cpp | 0.10s |

09 | Aman_khan | Cpp | 0.10s |

10 | iamsadee | Cpp14 | 0.10s |

11 | pulak_ict_mbstu | Cpp14 | 0.11s |

12 | ksohan | Cpp | 0.11s |

13 | Chayti_Saha98 | Cpp14 | 0.11s |

14 | kissu_pari_na | Cpp | 0.11s |

15 | Zeronfinity | Cpp14 | 0.12s |

16 | Sarwar05 | Cpp | 0.12s |

17 | shaft | Cpp | 0.12s |

18 | mno123 | Cpp | 0.12s |

19 | tariqiitju | Cpp14 | 0.12s |

20 | prodipdatta7 | Cpp14 | 0.12s |

21 | rayhan50001 | Cpp | 0.13s |

22 | mahbubcseju | Cpp14 | 0.13s |

23 | Double_O | Cpp14 | 0.13s |

24 | ssavi | Cpp14 | 0.13s |

25 | skmonir | Cpp14 | 0.13s |

26 | seyedssz | Cpp14 | 0.13s |

27 | Islam_Rafat | Cpp14 | 0.15s |

28 | nasif2587 | Cpp14 | 0.16s |

29 | njrafi | Cpp | 0.17s |

30 | showmic | Cpp14 | 0.17s |

31 | moshiur_cse15 | Cpp14 | 0.17s |

32 | sazal_dev | Cpp | 0.17s |

33 | clkjwdhc | Cpp | 0.17s |

34 | Mr_adnan | Cpp14 | 0.23s |

35 | simantaturja | Cpp | 0.23s |

36 | alttlprgrmmng | Cpp | 0.23s |

37 | swapnil | Cpp14 | 0.24s |

38 | emrul | Cpp14 | 0.24s |

39 | I_See_You | Cpp14 | 0.35s |

40 | bishal_biswas | Cpp | 0.65s |

Copyright © 2015-2016 Dev Skill.

Feedback
#### Your feedback is our precious!

## Thank you for providing feedback! Our developers will be happy :)

## Sorry there was a problem when submitting the feedback. Please try again. :(