P27043 [AtCoder] Walking NPCs
提高+
题目描述

Problem Description

joisino's next job is to verify the movement of NPCs in a game.
There are $ N $ NPCs standing on an infinitely long straight line that extends horizontally.
Each of them walks at a constant speed in a fixed direction.
A point on the line is represented by its coordinate $ x $, which indicates the distance to the right from a reference point.
At the start of the game, the $ i $th NPC is standing at coordinate $ X_i $ and moves $ V_i $ units per second.
More precisely, after $ t $ seconds from the start of the game, the $ i $th NPC will be at coordinate $X_i + V_i \times t$.
More than two NPCs may be at the same position simultaneously.
To verify if these NPC movements meet the game's specifications, joisino must answer $ Q $ queries.
The $ i $th query asks how many NPCs are between coordinates $ L_i $ and $ R_i $ after $ T_i $ seconds from the start of the game.
Note that NPCs at coordinates $ L_i $ or $ R_i $ are also considered to be between $ L_i $ and $ R_i $.
joisino's task is to write a program that answers all these queries.

Input Format

The input is given from the standard input in the following format:

$ N $ $ X_1 $ $ V_1 $ $ X_2 $ $ V_2 $ : $ X_N $ $ V_N $ $ Q $ $ T_1 $ $ L_1 $ $ R_1 $ $ T_2 $ $ L_2 $ $ R_2 $ : $ T_Q $ $ L_Q $ $ R_Q $

  • The first line contains an integer $N(1 \leq N \leq 10^5)$ representing the number of NPCs.
  • The next $ N $ lines contain the initial position $X_i(0 \leq X_i \leq 10^5)$ and the signed speed $V_i(-10^5 \leq V_i \leq 10^5)$ of the $ i $th NPC.
  • The next line contains an integer $Q(1 \leq Q \leq 10^5)$ representing the number of queries.
  • The following $ Q $ lines contain the query details: $T_i(0 \leq T_i \leq 10^5)$, $L_i(0 \leq L_i \leq 10^5)$, and $R_i(L_i \leq R_i \leq 10^5)$.

Output Format

The output consists of $ Q $ lines.
The $ i $th line should contain the answer to the $ i $th query.

Sample Input and Output

Sample Input #1

3
4 1
8 -3
1 2
4
1 3 4
3 0 10
2 2 6
0 1 5

Sample Output #1

1
2
3
2

Sample Input #2

4
0 50000
100000 -50000
0 2
100000 -3
6
0 50000 50000
1 50000 50000
2 50000 50000
20000 40000 40000
20001 39998 40001
20001 39997 40002

Sample Output #2

0
2
0
2
0
2

Sample Input #3

10
67812 -965
1766 93025
25587 -3294
14569 22
8830 203
50857 7
23407 -836
82660 80780
89781 1
86061 -1
10
97289 65405 94453
49386 73492 97497
75412 82840 94438
93076 43725 95471
18439 76630 93787
373 51319 92018
65554 30886 93533
66039 14298 95837
68359 90674 98196
31448 31879 98393

Sample Output #3

0
0
0
0
0
4
0
1
0
1
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 4 1 8 -3 1 2 4 1 3 4 3 0 10 2 2 6 0 1 5
样例输出
1 2 3 2