PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000139. Kỳ thi (Examination)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Kỳ thi (Examination)

Examination

Source: Japanese Olympiad in Informatics

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN students in an examination with two subjects: mathematics and informatics. Student ii scores SiS_i points in mathematics and TiT_i points in informatics.

Two professors jointly decide the passing criteria. The first professor requires a student to score at least AA in mathematics and at least BB in informatics, simultaneously. The second professor requires a student's combined score to be at least CC. A student passes only if all three conditions are satisfied.

The thresholds A,B,CA,B,C are not fixed. There are QQ possible criteria; criterion jj is a triple (Xj,Yj,Zj)(X_j,Y_j,Z_j) corresponding to A=XjA=X_j, B=YjB=Y_j, C=ZjC=Z_j.

For each criterion, count students ii simultaneously satisfying

$$S_i\ge X_j,\qquad T_i\ge Y_j,\qquad S_i+T_i\ge Z_j.$$

The students' scores never change, and each criterion is evaluated independently.

Input

  • The first line contains integers N,QN,Q: the number of students and the number of criteria.
  • Each of the next NN lines contains integers Si,TiS_i,T_i, the mathematics and informatics scores of student ii.
  • Each of the final QQ lines contains integers Xj,Yj,ZjX_j,Y_j,Z_j, the required thresholds for criterion jj.

Output

Print QQ lines. Line jj is the number of students meeting all three thresholds of criterion jj.

Subtasks

  • Subtask 1 (2 points): 1≤N,Q≤3 0001\le N,Q\le3\,000; 0≤Si,Ti,Xj,Yj≤1090\le S_i,T_i,X_j,Y_j\le10^9; 0≤Zj≤2⋅1090\le Z_j\le2\cdot10^9 for all valid indices.
  • Subtask 2 (20 points): 1≤N,Q≤100 0001\le N,Q\le100\,000; 0≤Si,Ti,Xj,Yj≤100 0000\le S_i,T_i,X_j,Y_j\le100\,000; Zj=0Z_j=0 for all valid indices.
  • Subtask 3 (21 points): 1≤N,Q≤100 0001\le N,Q\le100\,000; 0≤Si,Ti,Xj,Yj≤100 0000\le S_i,T_i,X_j,Y_j\le100\,000; 0≤Zj≤200 0000\le Z_j\le200\,000 for all valid indices.
  • Subtask 4 (57 points): 1≤N,Q≤100 0001\le N,Q\le100\,000; 0≤Si,Ti,Xj,Yj≤1090\le S_i,T_i,X_j,Y_j\le10^9; 0≤Zj≤2⋅1090\le Z_j\le2\cdot10^9 for all valid indices.

Examples

Example 1

Input

5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100

Output

2
4
1
1

Explanation

The five score pairs are (35,100),(70,70),(45,15),(80,40),(20,95)(35,100),(70,70),(45,15),(80,40),(20,95). For thresholds (20,50,120)(20,50,120), students 11 and 22 qualify with combined scores 135135 and 140140; student 33 and student 44 fail the informatics threshold, and student 55 has combined score only 115115: answer 22. For (10,10,100)(10,10,100), everyone but student 33 (total 6060) passes: 44. For (60,60,80)(60,60,80), only student 22 satisfies both subject thresholds: 11. For (0,100,100)(0,100,100), only student 11 has informatics score 100100: 11.